The mode switching included in this article is suitable for Firefox and other Gecko-based browsers, Safari, Chrome and other Webkit-based browsers, Opera, Konqueror, Internet Explorer for Mac, Internet Explorer for Windows, and browsers with built-in IE. Avoid mentioning the name of the browser engine and instead use the name of the most well-known browser of the engine.
This article focuses on the selection mechanism of patterns rather than recording the exact behavior of each pattern.
Here are a variety of different modes:
The pattern selection of text/html content depends on doctype sniffing (doctype sniffing, discussed later in this article). In IE8, the pattern also depends on other factors. However, by default in IE8, the patterns of non-intranet sites that are not provided on Microsoft's blacklist depend on the document type.
It is not an exaggeration to emphasize the difference in the precise behavior of patterns in each browser, even if there is a unified discussion in this article.
In Firefox, Safari, Chrome, and Opera, the application/xhtml+xml HTTP content type (not a meta element or doctype!) will trigger the XML pattern. In XML pattern, the browser tries to give XML documents the correct specifications to the extent that it is in the browser.
IE6, 7 and 8 do not support application/xhtml+xml, and so does Mac IE5.
In the WebKit-based Nokia S60 browser, the application/xhtml+xml HTTP content type cannot trigger the XML schema because the focus in mobile walled gardens is compatibility with irregular content. (Old-style mobile browsers cannot use real XML parsers because the non-standard content has been marked XML.)
Since Konqueror is not fully tested, I can't say exactly what will happen in this browser.
The patterns that some engines have have nothing to do with web content. For completeness, they are mentioned here only. Opera has a WML2.0 mode. WebKit on Leopard has a specific mode for legacy Dashboard widgets.
Here are the main effects of these patterns:
The text/html pattern mainly affects the CSS layout. For example, it is a quirk for tables not to inherit styles. In some browsers' quirk mode, the box model becomes the box model of IE5.5. This document does not list all layout quirks.
Quasi-standard mode (in browsers with this mode), only table cells containing pictures differ in high and standard mode.
In XML schema, selectors have different case-sensitive behaviors. Additionally, unique rules for HTML body elements cannot be applied to older browsers that do not implement the latest CSS2.1 changes.
There are also some quirks that affect HTML and CSS parsing and will cause web pages that meet standards to be parsed incorrectly. The layout of quirks determines whether these quirks are turned on. In any case, it is very important to understand the main similarities and differences of quirk patterns and standard patterns in CSS layout and parsing (non-HTML parsing).
Some people mistakenly call the standard mode strict parsing mode, which makes people misunderstand the browser's enforce HTML syntax rules and the browser's evaluation of the correctness of tags. This is not the case. Even when the standard mode layout takes effect, the browser will still make tag soup (tag soup, http://en.wikipedia.org/wiki/Tag_soup) correction work. (Before Netscape6 was released in 2000, Mozilla did have parsing patterns for enforcing HTML syntax rules. These patterns were abandoned incompatible with existing web content.)
Another common misconception is about XHTML parsing. It is usually believed that different parses are obtained using XHTML doctype. In fact, this is not the case. The content type is the same as the parser and HTML document used in the XHTML document of text/html. What browsers care about right now is that XHTML with document type text/html is just a tag soup with crouts (extra slashes everywhere).
Only when an XML document type document (for example: application/xhtml+xml or xmapplication/) is used, the parser will trigger the XML schema for parsing. The parser at this time is completely different from the HTML parser.
While the quirk pattern is mainly about CSS, some are about scripting. For example, in Firefox's quirk pattern, the HTML id attribute establishes object references to the global script scope just like in IE. The impact of scripts in IE8 is more worthy of attention than other browsers.
In the XML schema, some DOM APIs behave completely differently because the DOM API behavior of XML is not compatible with HTML behavior when defined.
Modern browsers use doctype sniffing to determine the engine mode of text/html documents. This means that the choice of schema is based on the document type declaration (or missing) starting with the HTML document. (This is not suitable for documents using XML document type.)
Document type declaration (doctype) is a syntax forgery of SGML. SGML is an old-style markup framework. HTML before HTML5 is defined based on it. In the HTML4.01 specification, the document type declaration describes the version information of HTML. Although the name is a Document Type Declaration and the HTML 4.01 specification describes version information, document type declarations do not apply to classify SGML or XML documents as specific types of documents, even if it looks like (because of the name). (More content is in the appendix)
Neither the HTML4.01 specification nor ISO 8879 (SGML) says anything about using document type declarations as engine mode conversion. Doctype sniffing is based on observation. When doctype sniffing is designed, most quirks do not have document type declarations or references to old DTDs. HTML5 accepts this fact and defines doctype as the only mode conversion in text/html.
A typical pre-HTML5 (pre-HTML5) document type declaration contains (separated by blanks) <!DOCTYPE string, a common identifier for the root element (html), a PUBLIC string, a DTD common identifier in quotes, a possible system identifier (URL) and a character for the same DTD. The document type declaration is before the document's root element starts the label.
Here is a simple guide to how to choose doctype when creating a new text/html document:
I do not recommend any XHTML doctype, as XHTML is considered harmful to use as text/html. Anyway, if you choose to use XHTML doctype, note that the XML declaration causes IE6 (but not IE7!) to trigger the quirk pattern.
A simple guide to application/xhtml+xml is never to use doctype. The web pages under this method are not strictly consistent with XHMTL1.0, but this does not matter. (Please see the appendix below)
A List Apart once introduced that IE8 will use meta-element-based pattern conversion as one of the factors for pattern selection, in addition to doctype. (See reviews by Ian Hickson, David Baron, David Baron again, Robert O'Callahan and Maciej Stachowiak.)
There are 4 modes for IE8: IE5.5 Quirk Mode, IE7 Standard Mode, IE8 Qual-Standard Mode and IE8 Standard Mode. The selection of mode depends on data from several aspects: doctype, meta elements, HTTP headers, regular download data from Microsoft, LAN domains, settings made by users, settings made by LAN administrators, modes of the parent framework (if any) and address bar compatible view button are triggered by users. (For other applications embedded in the engine, the pattern also depends on the embedded application.)
Fortunately, IE8 will generally use doctype sniffing like other browsers if the following occurs:
Except for the two cases regarding X-UA-Compatible, IE8 performs doctype sniffing like IE7. IE7 emulation (IE7 emulation) is called compatible view.
In the case of X-UA-Compatible, IE8 behaves completely differently than other browsers. I would like to see the appendix or flowchart in PDF and PNG formats on this page.
Unfortunately, there is no HTTP header or meta tag for X-UA-Compatible, and even with the appropriate doctype, IE8 allows users to accidentally reduce the page from IE8's standard mode to IE7 mode, which is a simulated IE7 standard mode. Worse, LAN administrators can do the same. Microsoft can also blacklist all domain names you use.
To deal with these effects, doctype is not enough, you need X-UA-Compatible HTTP header and meta tag.
The following simple guide is for new text/html documents that already have doctype trigger standard mode or quasi-standard mode in other browsers for how to choose X-UA-Compatible HTTP header or meta tag:
Please do not bring doctype sniffing to XML.
Doctype sniffing is to solve a problem of labeled chowder soup using a chowder soup-like method. Doctype sniffing is a tentative approach designed after the release of HTML4 and CSS2 specifications, which distinguishes outdated documents from documents to match behaviors that their authors might expect.
Occasionally it is suggested to use doctype sniffing on XML to schedule different processing, identify the vocabulary being used, or to activate features. This is a bad idea. Scheduling and vocabulary recognition should be based on namespace, while feature activation should be based on explicit processing instructions or elements.
The whole idea of well-formedness is to introduce DTD parsing that allows XML, and promote doctype-free documents. In formal cases, two XML documents have the same canonical form and the application processes them differently (and not because there is no choice to handle external entities), the application may be broken. In practice, if two XML documents cause the same content to be reported (qnames ignore) to the SAX2 content processor and the application processes the document differently, the application may be broken. Considering that as a web author it is impossible to believe that everyone will parse their pages using XMLprocessors that address additional entities (even if some browsers seem to do so, as they map certain public identifiers to a DTD that defines the entity with an abridged), inserting doctype into XML for use in the Web is meaningless and often leads to cargo cultish habits. (You still use the DTD override feature of the W3C validator to verify a DTD, although the W3C validator will say the result is only temporary. Or better yet, you can use relaxing NG verification, which does not pollute the document referenced by the pattern.) It is very silly to require doctype for sniffing, even if that is a workaround in HTML practice.
Furthermore, when a low-level specification defines two equal things, a high-level specification should not try to give them different meanings. Please consider <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>. If the public identifier is deleted, the same DTD is still specified, so doctype <!DOCTYPE html SYSTEM http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> means the same as the previous doctype. Should they be sniffed differently? It can be further theory. Suppose copy to example.com a DTD called foobar.dtd: <!DOCTYPE html SYSTEM http://example.com/foobar.dtd>. How to sniff this? It should have the same meaning. Even the entire DTD can be posted in the document.
In other words, if there is #include foo.h, you should not bind any black magic to the name foo.h, as it should allow copying of the contents of foo.h into the document or copying foo.h into bar.h and representing #include bar.h.
The reason I'm not worried about HTML and SGML constructing the same parameters is that the web browser does not use a real SGML parser to parse HTML, so I think it's useless to masquerade as SGML for processing. Anyway, if you don't believe it yet, please read W. Eliot Kimber's article on this matter comp.text.sgml
In the following table, the quirk pattern, the standard pattern and the quasi-criteria are represented as Q, S, and A, respectively. When the browser has only two modes, the standard mode is marked as S if the row height of the table cell is consistent with the standard mode performance of Mozilla, and the standard mode is marked as A if the row height of the table cell is consistent with the standard mode performance of Mozilla.
Please note that XHTML serving using the XML content model is rendered in XML mode.
The purpose of this table is not to say that all doctypes in the table are reasonable choices for creating new pages. The purpose of this table is to show what kind of data my recommendations are based on.
The following abbreviation symbols are used for column titles:
| Doctype | NS6 | Old Moz | Moz & Safari & Opera10 & HTML5 | Opera9.0 | IE8 & Opera9.5 | IE7 & Opera7.10 | IE6 & Opera7.0 | Mac IE5 | Konq3.2 |
|---|---|---|---|---|---|---|---|---|---|
| None | Q | Q | Q | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 3.2 Final//EN> | Q | Q | Q | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN> | S | S | S | S | S | A | A | Q | A |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0//EN http://www.w3.org/TR/html4/strict.dtd> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN> | Q | Q | Q | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> | Q | Q | Q | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> | S | S | A | A | A | A | A | A | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd> | Q | S | A | A | A | A | A | A | Q |
| <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> | Q | Q | Q | Q | A | A | A | A | Q |
| <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE html PUBLIC -//W3C//DTD XHTML Basic 1.0//EN http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> | S | S | S | S | S | A | A | A | A |
| <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> | S | S | A | A | A | A | A | A | Q |
| <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd> | S | S | S | S | S | A | Q | A | Q |
| <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML Basic 1.0//EN http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd> | S | S | S | S | S | A | Q | A | Q |
| <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> | S | S | S | S | S | A | Q | A | Q |
| <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> | S | S | A | A | A | A | Q | A | Q |
| <!DOCTYPE HTML PUBLIC ISO/IEC 15445:2000//DTD HTML//EN> | Q | S | S | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC ISO/IEC 15445:2000//DTD HyperText Markup Language//EN> | Q | S | S | S | S | A | A | A | Q |
| <!DOCTYPE HTML PUBLIC ISO/IEC 15445:1999//DTD HTML//EN> | S | S | S | Q | Q | Q | Q | Q | Q |
| <!DOCTYPE HTML PUBLIC ISO/IEC 15445:1999//DTD HyperText Markup Language//EN> | S | S | S | S | S | A | A | A | Q |
| <!DOCTYPE html> | Q | S | S | S | S | A | A | A |
Moziila's doctype sniffing code was significantly modified in October 2000, September 2001 and June 2002. The states established by Mozilla (and Netscape 6.x) described in this document can be seen on ftp.mozilla.org since 2000.10.19. This document does not address how doctype sniffing works in Mozilla M18 (and Netscape 6.0 PR3). Safari's doctype sniffing code has also been greatly modified since the first public beta. This document does not include behaviors earlier than version V73, also called 0.9.
The doctype sniffing code before Konqueror3.5 seems to come from an early version of Safari. Konqueror now matches Safari, and its doctype sniffing code comes from Mozilla.
As can be seen from the table, Opera's doctype sniffing is changing from a regular IE-like to a Mozilla-like, although Opera9.5 and 9.6 are on the way backwards. Meanwhile, the layout behavior of Opera quirk mode has been switched from imitating IE6's quirk mode to Mozilla's quirk mode.
These steps can be seen through the flowcharts in PDF and PNG formats.
Thanks to Simon Pieters, Simon Pieters and Anne van Kesteren for helping me correct the pattern tables and their comments for various Opera versions. Thanks to Simon Pieters for making another IE8 flowchart.