Selection mechanism of DOCTYPE mode by well-known browsers

Time:2021-11-10

Document scope

The mode switching included in this article is applicable to 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 embedded ie. Avoid mentioningThe name of the browser engineInstead, use the name of the most famous browser using the engine.

This paper focuses on the selection mechanism of patterns, rather than recording the exact behavior of each pattern.

pattern

The following are different modes:

The content type is text / HTML

The mode selection of text / HTML content depends on DOCTYPE sniffing,This article is discussed later)。 In IE8, the mode also depends on other factors. However, by default in IE8, the mode of non intranet sites that are not on the blacklist provided by Microsoft depends on the document type.

It’s not too much to emphasize the differences in the precise behavior of patterns in each browser, even if it’s discussed uniformly in this article.

Quirks mode
In quirky mode, in order to avoid “destroying” pages created according to popular practices in the late 1990s, browsers violate modern web format specifications. Different browsers implement different quirks. In Internet Explorer 6, 7 and 8, quirky mode is effectively frozen in ie5.5. In other browsers, quirky mode is a small offset from the standard mode.
If you are creating new web pages, you should comply with relevant specifications (especially CSS 2.1) and use standard patterns.
Standards mode
In standard mode, the browser attempts to properly handle the standard compliant documents to the extent that they are in the specified browser.
Different browsers follow different stages, so the standard pattern is not a single goal.
HTML5 calls this mode “no quirks mode.”
Almost standards mode
Irefox, Safari, chrome, opera (starting from 7.5) and IE8 also have a mode called “quasi standard mode”, which implements the vertical size of table cells according to the traditional practice rather than strictly following the CSS2 specification. Mac IE5, windows IE6 and 7, pre opera 7.5 and Konqueror do not need quasi standard mode because they do not strictly follow the CSS2 specification to realize the vertical size of table cells in their respective standard modes. In fact, their standard schema is closer to Mozilla’s Quasi standard schema than Mozilla’s standard schema.
HTML5 calls this mode “limited quirks mode”.
IE7 mode
IE8 has a mode, which mainly freezes the copy of IE7 standard mode. Other browsers do not have such a mode, and this mode is not specified by HTML5.

Schema with content type of application / XHTML + XML (XML schema)

In Firefox, Safari, chrome and opera, the application / XHTML + XML HTTP content type (neither meta element nor DOCTYPE!) triggers the XML schema. In XML schema, the browser tries to deal with XML documents correctly in the specification 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 Nokia S60 browser based on WebKit, the application / XHTML + XML HTTP content type cannot trigger the XML schema, because in the mobile walled gardens, the focus is on the compatibility of non-standard content. (Older “mobile browsers” cannot use real XML parsers, because the nonstandard content has been marked as XML.)

Since Konqueror was not fully tested, I couldn’t say exactly what would happen in this browser.

Non web modes

Some engines have patterns that are independent of web content. For completeness, they are only mentioned here. Opera has a wml2.0 mode. WebKit on leopard has a specific pattern for legacy dashboard widgets.

influence

The following are the main impacts of these modes:

layout

Text / HTML mode mainly affects CSS layout. For example, it is a quirk that tables do not inherit styles. In the quirky mode of some browsers, the box model becomes the box model of ie5.5. This document does not list all layout quirks.

In quasi standard mode (in browsers with this mode), the height of table cells containing only pictures is different from that in standard mode.

In XML schema, selectors have different case sensitive behavior. In addition, the unique rules for HTML body elements cannot be applied to older browsers that do not implement the latest css2.1 changes.

analysis

There are also some quirks that affect the parsing of HTML and CSS, and will lead to the wrong parsing of standard web pages. The quirks layout determines whether these quirks are turned on. In any case, it is important to understand the main similarities and differences between quirky 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 that browsers enforce HTML syntax rules and use browsers to evaluate the correctness of tags. This is not the case. Even when the standard mode layout takes effect, the browser will still make tag soup, http://en.wikipedia.org/wiki/Tag_soup )Correction work. (before the release of Netscape 6 in 2000, Mozilla did have parsing patterns to enforce HTML syntax rules. These patterns were incompatible with existing web content and abandoned.)

Another common misconception is about XHTML parsing. It is generally believed that XHTML DOCTYPE can get different parsing. In fact, this is not the case. XHTML documents with text / HTML content type use the same parser as HTML documents. At present, the browser is concerned that XHTML with the document type of text / html is only “tag soup with croutons” (with additional slashes everywhere).

Only when a document of XML document type (for example: application / XHTML + XML or xmapplication /) triggers XML schema to parse, the parser is completely different from the HTML parser.

script

Although quirky patterns are mainly about CSS, some are about scripting. For example, in Firefox’s quirky mode, the HTML ID attribute establishes the object reference of the global script scope as in ie. The impact of scripts in IE8 deserves more attention than other browsers.

In XML schema, the behavior of some DOM APIs is completely different, because the DOM API behavior of XML is not compatible with the behavior of HTML when it is defined.

DOCTYPE sniffing (also called DOCTYPE conversion)

Modern browsers use DOCTYPE sniffing to determine the engine mode of text / HTML documents. This means that the mode selection is based on the document type declaration (or missing) at the beginning of the HTML document. (this is not appropriate for documents that use XML document types.)

Document type declaration (DOCTYPE) is the syntax forgery of SGML. SGML is an old markup framework, and HTML before HTML5 is defined according to it. In the HTML 4.01 specification, the document type declaration describes HTMLVersion information。 Although the name is “document type declaration” and the HTML 4.01 specification describes “version information”, document type declaration does not apply to classifying SGML or XML documents as specific types of documents, even if it looks like (because of the name). (More information is provided in the appendix

Neither the html4.01 specification nor ISO 8879 (SGML) says anything about using document type declarations as engine schema transformations. DOCTYPE sniffing is based on observation. When DOCTYPE sniffing is designed, most quirky documents have neither document type declaration nor reference to old DTDs. HTML5 accepts this fact and defines DOCTYPE as the only schema transformation in text / HTML.

A typical pre HTML5 (pre-html5) document type declaration contains (separated by white space) a “<! DOCTYPE” string, a common identifier of the root element (“HTML”), a “public” string, a DTD public identifier in quotation marks, a possible system identifier (URL) of the same DTD, and the character “>”. The document type declaration precedes the start tag of the root element of the document.

Select DOCTYPE

text/html

Here is a simple guide on how to select a DOCTYPE when creating a new text / HTML document:

Standard mode, cutting-edge verification
<!DOCTYPE html>
If you want toverificationsuch as<video><canvas>And new features like aria, then it’s right to do so. Note that the valid definition of HTML5 is still changing, please make sure to test image alignment in Firefox, Safari, chrome, opera 9 or Opera 10. It is not enough to test image alignment in Internet Explorer. In any case, please ensure that it is also tested in IE8.
Standard mode, more stable verification target
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
This DOCTYPE also triggers the standard pattern, and the valid definition of 10-year-old HTML 4.01 is stable. Make sure to test image alignment in Firefox, Safari, chrome, opera 9, or Opera 10. It is not enough to test image alignment in Internet Explorer. In any case, please ensure that it is also tested in IE8.
Use the standard mode, but still verify the deprecated tags or use slice images in the table layout and do not want to repair them.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
It triggers the quasi standard mode (and the full standards mode in the old Mozilla). Note that if you migrate to HTML5 later, the layout based on sliced images implemented with tables may be differentDestroyed(and so does the full standard model).
Deliberately use quirky mode
No DOCTYPE.
Please don’t do that. The design deliberately made for the quirky mode will perplex you. In the future, no one even cares about windows IE6 (no one cares about Netscape 4. X and IE5). Designing for quirky patterns is a bad idea. believe me.
If you want to still support Windows IE6, make a special hack use of itconditional comments Better than taking other browsers back to quirky mode.

I don’t recommend any XHTML DOCTYPE becauseXHTML used as text / html is considered harmful。 Anyway, if you choose to use XHTML DOCTYPE, please note that XML declaration will cause IE6 (but not IE7!) to trigger quirky mode.

application/xhtml+xml

The simple guide to application / XHTML + XML is never to use DOCTYPE. The web pages in this way are not “strictly consistent” xhmtl 1.0, but this is not important. (please look at the back.)appendix

IE8 complications

A list apart once introducedIn addition to DOCTYPE, IE8 uses schema transformation based on meta elements as one of the factors for schema selection. (please seeIan HicksonDavid BaronDavid Baron againRobert O’CallahanandMaciej StachowiakComments.)

IE8 has four modes: ie5.5 quirky mode, IE7 standard mode, IE8 quasi standard mode and IE8 standard mode. The mode selection depends on the data from several aspects: DOCTYPE, meta element, HTTP header, periodic download data from Microsoft, LAN domain, settings made by users, settings made by LAN administrators, mode of parent framework (if any) and address bar compatibility View button triggered by users. (for other applications embedded in the engine, the mode also depends on the embedded application.)

Fortunately, IE8 generally uses DOCTYPE sniffing like other browsers if:

  • The author did not set the x-ua-compatible HTTP header
  • The author did not set the x-ua-compatible meta tag
  • Microsoft did not place the domain name of the site in the blacklist
  • The LAN administrator did not place the site inblacklistupper
  • The user has not pressed the compatibility View button (or otherwise added to a specific user blacklist)
  • The site is not in a LAN domain
  • The user did not choose to display all sites in IE7
  • The page is not embedded in a compatible mode page through the frame

Except for the above two cases about x-ua-compatible, IE8 performs DOCTYPE sniffing like IE7. IE7 simulation is called compatibility view.

In the case of x-ua-compatible, IE8 behaves completely different from other browsers. Want to see this pageappendixorPDFandPNGFlow chart in format.

Unfortunately, without the HTTP header or meta tag of x-ua-compatible, even if the appropriate DOCTYPE is used, IE8 allows users to inadvertently reduce the page from IE8 standard mode to IE7 mode, which is a simulated IE7 standard mode. Worse, LAN administrators can do the same. Microsoft can also blacklist all the domain names you use.

In order to deal with these effects, DOCTYPE is not enough. You need x-ua-compatible HTTP header and meta tag.

The following simple guide is about how to select x-ua-compatible HTTP headers or meta tags for new text / HTML documents with DOCTYPE triggering standard mode or quasi standard mode in other browsers:

Your domain name is not on Microsoft’s blacklist. You pay more attention to the fact that there is no annoying thing exclusive to the browser, rather than ensuring that users can’t go back and present IE7.
You do not need to include x-ua-compatible HTTP headers or meta tags.
Your domain name is in Microsoft’s blacklist. Because other authors in your domain name destroy the site, users may enable compatible view for the whole domain. You are worried that Google or Digg will embed your site with frame, or you want to ensure that users cannot use compatible view
First, include the following meta element in your page (which is illegal in HTML5)<meta http-equiv=”X-UA-Compatible” content=”IE=Edge”>(before any script element), or set the following HTTP header: x-ua-compatible: ie = edge
Your site works in IE7 but is broken in IE8
First, include the following meta element in your page (which is illegal in HTML5)(before any script element), or set the following HTTP header: x-ua-compatible: ie = emulateie7, and then repair your site that does not rely on non-standard IE7 behavior and migrate to IE = edge.

Related links

Addendum: supplication to XML implementers and specification authors

Please do not bring DOCTYPE sniffing to XML.

DOCTYPE sniffing is a tag soup like method to solve a tag soup problem. DOCTYPE sniffing is a heuristic designed after the release of html4 and CSS2 specifications. It distinguishes outdated documents from documents to meet the behavior that their authors may expect.

Occasionally, it is suggested to use DOCTYPE sniffing on XML to schedule different processes, identify vocabularies in use, or activate features. That’s a bad idea. Scheduling and vocabulary recognition should be namespace based, while feature activation should be based on explicit processing instructions or elements.

The whole idea of well formedness is to introduce DTD free parsing of XML and promote DOCTYPE free documents. Formally, two XML documents have the same canonical form and the application processes them differently (and the difference is not because there is no choice to process external entities), the application may be broken. In practice, if two XML documents cause the same content to be reported (QNames ignored) to sax2Content processorAnd the application processes documents differently, and the application may be damaged. Considering that as a web author, you can’t believe that everyone will use the XML processor to solve additional entities to parse their pages (even if some browsers seem to do so because they will map a certain public identifier to a DTD with truncated defined entities), inserting DOCTYPE into XML for the web is meaningless and usually leads to cargo culture habit. (you still use the W3C validator)DTD overlay functionTo validate a DTD, although the W3C validator will say that the result is only temporarily valid. Or better yet, you can useRelax ng verification, it does not contaminate the documents referenced by the schema.) It’s foolish to ask for DOCTYPE for sniffing, even if that’s the solution in HTML practice.

In addition, 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 the DOCTYPE<!DOCTYPE html SYSTEM “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>Indicates the same as the previous DOCTYPE. Should they be sniffed differently? The theory can be further. Suppose you copy a DTD called foobar.dtd to example.com:<!DOCTYPE html SYSTEM “http://example.com/foobar.dtd”>。 How to sniff? It should mean the same thing. Even the entire DTD can be pasted in the document.

In other words, if there is #include “foo. H”, you should not bind any black magic to the name foo. H, because it should allow the content of foo. H to be copied into the document or foo. H to bar. H and represent #include “bar. H”.

The reason why I don’t worry about html and SGML constructing the same parameters is that web browsers won’t use a real SGML parser to parse HTML, so I don’t think it’s useful to disguise as SGML for processing. Anyway, if you don’t believe it, please seeW. Eliot Kimber’s article on this comp.text.sgml

Appendix: how to handle some DOCTYPES in text / HTML

In the following table, quirky mode, standard mode and quasi standard are represented as Q, s and a respectively. When the browser has only two modes, if the row height of the table cell is consistent with Mozilla’s standard mode, the standard mode is marked as “s”; if the row height of the table cell is consistent with Mozilla’s Quasi standard mode, it is marked as “a”.

Note that XHTML served using the XML content model is rendered in XML schema.

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 recommendation is based on.

The following abbreviations are used for column headings:

NS6
Mozilla 0.6… 0.9.4 and Netscape 6.0… 6.2.3
Old Moz
Mozilla 0.9.5 to 1.1 alpha and Mozilla 1.0
Moz & Safari & Opera 10 & HTML5
Mozilla 1.0.1, Mozilla 1.1 beta and later, Firefox to netscape 7, Safari 0.9 to safari 4.0 Beta, Opera 10, chrome, Konqueror 3.5, HTML5
Opera 9.0
Opera 9.0…9.20
IE 8 & Opera 9.5
Default IE8 without x-ua-compatible and compatible mode coverage (in this case, “a” means IE8 quasi standard mode), opera 7.5… 8.54 and 9.5… 9.6
IE 7 & Opera 7.10
IE7, IE8 in compatible mode without x-ua-compatible coverage (in this case, “a” means IE7 mode) and opera 7.10… 7.23
IE 6 & Opera 7.0
Windows IE 6 and opera 7.0… 7.03
Mac IE 5
Mac IE 5.0…5.2.3
Konq 3.2
Konqueror 3.2.2… 3.3 (may also include 3.1… 3.2.1; I’m not sure)
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  

Historical records

Mozila’s DOCTYPE sniffing code was significantly modified in October 2000, September 2001 and June 2002. The establishment status of Mozilla (and Netscape 6. X) described in this document can be seen on ftp.mozilla.org since October 19, 2000. This document does not cover 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 known as 0.9.

The DOCTYPE sniffing code before Konqueror 3.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 regularly changing from IE like to Mozilla like, although opera 9.5 and 9.6 are on the way back. At the same time, the layout behavior of opera’s quirky mode has been transformed from the quirky mode following IE6 to Mozilla’s quirky mode.

Appendix: mode selection of IE8

Start: enter “x-ua-compatible meta?”
X-UA-Compatible meta?
Ie = 7: use IE7 standard
Ie = emulateie7: enter “quirky or no DOCTYPE? (compatibility mode)”
Ie = IE8 or IE = IE7 or IE = a or IE = emulateie8 or no or first script: enter “x-ua-compatible HTTP header?”
Ie = 8 or IE = edge or IE = 99 or IE = 9.9: enter “quasi standard mode?”
Ie = 5: use quirky mode (ie5.5)
X-ua-compatible HTTP header?
Ie = 7: use IE7 standard mode
Ie = emulateie7: enter “quirky or no DOCTYPE? (compatibility mode)”
Ie = IE8 or IE = IE7 or IE = a or IE = emulateie8 or not: enter “show all sites… Preset?”
Ie = 8 or IE = edge or IE = 99 or IE = 9.9: enter “quasi standard mode?”
Ie = 5: use quirky mode (ie5.5)
Quirky mode or no DOCTYPE? (compatibility mode)
Yes: use quirky mode (ie5.5)
No: use IE7 standard mode
Show all sites… Preset?
Yes: enter “quirky mode or no DOCTYPE? (compatibility mode)”
No: enter “display LAN site… Preset?”
Show LAN sites… Preset?
Yes: enter “site in LAN domain?”
No: enter “the domain name is on the list maintained by Microsoft?”
Is the domain name on the list maintained by Microsoft?
Yes: enter “quirky mode or no DOCTYPE? (compatibility mode)”
No: enter “embedded with frame by compatibility mode page?”
Embedded by compatibility mode page with frame?
Yes: enter “quirky mode or no DOCTYPE? (compatibility mode)”
No: enter “compatibility mode button pressed?”
Compatibility mode button pressed?
Yes: enter “quirky mode or no DOCTYPE? (compatibility mode)”
No: enter “quirky mode or no DOCTYPE? (IE8)”
Quirky mode or no DOCTYPE? (IE8)
Yes: enter “using quirks mode (ie5.5)”
No: enter “quasi standard mode?”
Quasi standard mode?
Yes: use IE8 quasi standard mode
No: use IE8 standard mode

These steps can be passedPDFandPNGSee the flow chart in format.

Acknowledge

Thank Simon Pieters, Simon Pieters and Anne van kesteren for helping me correct the schema tables of various opera versions and their comments. Thank Simon Pieters for making another IE8 flowchart.