What is quirks mode?
At the introduction of CSS, two main browsers on the market, Microsoft’s Internet Explorer 4 and Netscape 4 did not fully support it. Netscape did horribly broke the entire standard, while IE came closer to it but with some important bugs. So, the developers had to create a different version of CSS for every browser, in order to be sure that their pages would render correctly on every one of them.
In time, when the standards became more important, the developers had to choose whether to create the next version of browser closer to the W3C standards, but disable support for the older sites, or creating it conforming to the internal standards, but which would preserve the quality of the sites created specifically for this browser. So the creation of standard-complying browsers would bring problems. But on the other hand, remaining on the old standards would create a state of confusion, similar to the Browser Wars Era.
In such a way, it was decided that every browser would be able to work in two modes: quirks mode, that represents the old standards supported by the browser, and strict mode which fully complies with the W3C standards. IE Mac was the first browser to support these modes, but other browsers like IE Windows 6, Mozilla, Safari and Opera also started the support of these modes. IE5 and older browsers, such as Netscape 4 are permanently working in quirks mode.
Now another problem appears: how does the browser choose to work in strict mode or in quirks mode. The problem was solved through “doctype switching”. Any HTML and XHTML documents, according to the standards, must contain a doctype, which tells to the browser which flavour of (X)HTML it is being used on the page. As the older pages do not contain a doctype, its absence triggers the quirks mode. On the other side, the majority of doctypes triggers the browser in strict mode. Any browser has its own list of doctypes and in such a way, basing on the doctype information, it can switch itself from quirks mode to strict mode and vice versa.

