The previous article mainly talked about the composition of HTML document , while superficially touching it In order to understand the concept of "tag omission", this article will conceptually introduce the first important element that appears in HTML documents - DOCTYPE
The so-called DOCTYPE is originally the concept of XML. A specific syntax is used as a kind of metadata to describe the elements allowed to appear in XML documents, as well as the composition of each element, nesting rules, etc. A more detailed result can be obtained in WIKI
But in HTML, DOCTYPE has some different effects, one of which is the famous function of triggering the browser's standards mode. That is, if there is no DOCTYPE, the browser will enter a weird mode called Quirks mode. State, in this mode, the browser's box model, style parsing, layout, etc. are different from those specified by the standard.
It should be noted that the so-called HTML standard and DOM standard. etc., only stipulates the concepts and behaviors in standard mode. As mentioned in the document structure, DOCTYPE is an absolutely indispensable part of an HTML document, so there is no concept of "Quirks mode" at all. Because the standard does not make any provisions for Quirks mode, different browsers handle Quirks mode differently, and it is even more difficult to apply Quirks mode.
In the HTML4 standard, DOCTYPE is included in the chapter "HTML Version Information". In this chapter, the standard specifies 3 types of DOCTYPE:
#.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <title>I'm not a frameset</title> </head> <body> <p>So what?</p> </body> </html>
Refuse to render this page? No, browsers don’t dare to do this. In the fierce market competition, if some pages cannot be rendered because of this, they can only watch the market share being injected into other fields. So the browser can at most report a weak warning in protest, but it still has to parse the document and render it correctly.
HTML5
, DOCTYPE has undergone a major change... has arrived in HTML5. I believe most people already know this change, that is HTML5 simplifies the declaration of DOCTYPE, only is required.As mentioned above, in the HTML4 era, standard setters have realized that DOCTYPE is not very helpful for browser rendering, except for boring w3c
validator
One or more spaces. For the definition of spaces, please refer to the explanation in Introduction.
charactersHTML
, also case-insensitive.
1 or more spaces.
End tag, that is, >. </ol>
<li><p>DOCTYPE no longer recommended - deprecated doctype</p></li>
<li>
<p>The so-called several DOCTYPEs in the HTML4 era, their composition is as follows: </p>
<p>In the standard, there is a strict correspondence between Public ID and System ID. If the specified System ID cannot have a Public ID, the 8th optional content above cannot exist. HTML5 completely abandons the transitional and framework DOCTYPE in HTML4, and integrates the DOCTYPE declaration of XHTML, resulting in the following 6 combinations: </p>
</li>
<ul class=" list-paddingleft-2" style="list-style-type: square;">
<li><p>##< ;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN"><code>
A pair of quotation marks or single quotation marks (must match before and after), put a System ID corresponding to the previous Public ID in the quotation marks.
1 or more spaces.
characters
HTML1 or more spaces.
characters
PUBLICContinue with 1 or more spaces.
A pair of quotation marks or single quotation marks (must match before and after), put a Public ID in the quotation marks.
Optional content:
1 or more spaces.
End tag, that is,
>.As the name suggests, DOCTYPE is completely prepared for compatibility with the historical heritage of long ago. , there is no way to even verify what kind of "tool" will create this kind of DOCTYPE... The composition of legacy tool-type DOCTYPE is as follows:
, basically there is nothing worth changing except the case.
1 or more spaces.
characters
HTML1 or more spaces.
characters
SYSTEMContinue with 1 or more spaces.
A pair of quotation marks or single quotation marks (must match before and after), put a text
about:legacy-compat1 or more spaces.
>.
Realistic details
For IE6-9, if there is a comment before DOCTYPE, it will enter Quirks mode.
The above is the detailed content of HTML5 standards learning-DOCTYPE header analysis. For more information, please follow other related articles on the PHP Chinese website!