Doctype switching and standards compliance: An overview

On this page: The article, Links to more Doctype switching resources
Next page: Table of Doctypes and their respective layout modes

What is doctype switching

Summary: Some modern browsers have two rendering modes. Quirk mode renders an HTML document like older browsers used to do it, e.g. Netscape 4, Internet Explorer 4 and 5. Standard mode renders a page according to W3C recommendations. Depending on the document type declaration present in the HTML document, the browser will switch into either quirk mode or standard mode. If there is no document type declaration present, the browser will switch into quirk mode.

Brief update, February 2003

Opera 7 now also features a Doctype switch. See the Opera documentation for details. Opera chooses layout mode the same way as IE6. Opera 7.02 even has the same <?xml ...?> bug: <?xml version="1.0" encoding="UTF-8"?>, will cause the browser to use quirk mode.

Brief update, January 2003

For the sake of completeness: For some months now, Mozilla has had a new "almost standard" mode. See Mozilla's DOCTYPE sniffing for details.

And as you may or may not know, Internet Explorer has always had (and still has in version 6) a very regrettable bug: If there is anything before the DOCTYPE declaration, it will switch to quirk mode. This means that the usual XML declaration, e.g. <?xml version="1.0" encoding="UTF-8"?>, will cause the browser to use quirk mode.

The situation

  1. First, the good news:The latest versions of browsers like Opera, Netscape Communicator, and Internet Explorer have better support for W3C recommendations than their predecessors.
  2. Now the bad news: Most web pages were written for compatibility with popular browsers like Netscape 4 and Internet Explorer 4 and 5. This included using proprietary HTML elements and attributes, or relying on certain bugs. Examples for proprietary elements: layer, marquee, blink. Examples for proprietary attributes, or incorrect use of attributes: bordercolor, marginwidth, marginheight, topmargin, leftmargin. Example for reliance on a known bug: The CSS box model in Internet Explorer 5 / PC, which does not follow the CSS standards.

Combine 1 and 2, and you end up with two scenarios:

  1. Pages that don't comply with W3C recommendations, or were written to accommodate certain bugs, will look right in the old browsers, but might not look right in the new browsers.
  2. Pages that do comply with W3C recommendations might not look right in the old browsers, but will look right in the new browsers.

The problem

Ignoring this situation would have been the simplest solution. But browser vendors were aware that both authors and visitors will blame the browser if the old pages, which used to look fine in the old browser, all of a sudden don't look right in the new browser. Therefore, compliance with W3C recommendations became a problem.

The solution

Therefore, both Microsoft and Mozilla decided to do something about it. The solution was two different rendering modes: The first mode, known as quirk or compatible mode, renders the pages like the old, incompatible browsers used to. The second mode, known as standard or compliant mode, renders them like the pages should be rendered according to W3C recommendations. The technical details about these modes can be found in the browser documentation mentioned below.

The big question now is: How does the browser decide which rendering mode he will use for a particular page? This question could be answered in a number of ways, of course. Both Microsft and Mozilla decided to use the document type declaration (or the lack thereof): If the document type declaration is of type a, then switch into standard mode. If the document type definition is of type b, or if no document type definition is found, then switch into quirk mode.

That's how it stands today. For further information use the links listed below: W3C Doctypes, Browser documentation, Articles and opinions, Standard support. For a tabular summary of all browsers that do doctype switching and, most important, when they switch into which mode, see the doctype switch table, a work in progress.

Doctype switching links

The W3C doctypes
Document Type Declaration W3C HTML4 Recommendation: The document type declaration names the document type definition (DTD) in use for the document
TR/REC-html32 The HTML3.2 Final Doctype
TR/html4/ The HTML4 Doctypes
TR/xhtml1 The XHTML1 Doctypes
The browser documentation
Mozilla's Quirks ModeDavid Baron: Comprehensive documentation of Doctype sniffing and quirks mode in Mozilla workshop Doctype switching in IEX6 htmlparser source Source code: Doctype switching in Mozilla
quirk.css Mozilla quirk css: Stylesheet for "quirk" mode
hsivonen Henri Sivonen: Things to Take into Account When Moving to Standards-Compliant HTML and CSS Authoring
Mozilla quirk list David Baron: Changes between Mozilla's standards mode and quirks mode
Articles and opinions on doctype switching
'Standards' vs 'Quirks' Serving XHTML 1.0: The W3C's short explanation of standards vs quirks mode article Eric Meyer about doctype switching in IEX5 / Mac Henri Sivonen about doctype switching in Mozilla and IE5/Mac
David Baron David Baron on Mozilla Doctype Sniffing; according to him, this document is outdated. But it's a good discussion of the concept, and has links to more current documents Known issues with support of web standards in Mozilla and Netscape. Because many developers first perceived doctype switching as a bug, this feature is also discusssed here.
webmonkey Jeffrey Veen about IEX6 Preview Working with HTML - Doctype switching explained
mozilla.layout Arjun Ray: Sniffing Doctype Declarations is Bogus

Somewhat related: Standard support

Mozilla faq Gecko on standards Known CSS2- bugs for the Gecko engine
html.cssMozilla html css: Stylesheet for HTML
forms.cssMozilla forms.css: Stylesheet for forms
Netscape Netscape about CSS in Netscape; not necessarily entirely unbiased
ekrockhome Eric Krock from Netscape discusses standards support.
Opera specs CSS in Opera 5
Internet Explorer css referenceCSS Attributes Reference for IEX5 and IEX5.5, including MS-proprietary extensions workshop CSS in IEX6 Public Preview; includes doctype switch explanations workshop Microsoft Web Workshop on CSS for IEX

© Matthias Gutfeldt, 2003. Steal the code, not the content.