Home > Article > Web Front-end > HTML5 standards learning-DOCTYPE header analysis
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:
a73094d7f9503c885bdc52b97b2daeb7#.
<!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>
04a0d55efbbfd646a993fbc01f262c57
elements. , corresponding to the use of standard HTML structures that should be specified by strict mode or transition mode. So what can the browser do in this situation?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, onlyAs mentioned above, in the HTML4 era, standard setters have realized that DOCTYPE is not very helpful for browser rendering, except for boring w3c
validator
DOCTYPE no longer recommended - deprecated doctype
The so-called several DOCTYPEs in the HTML4 era, their composition is as follows:
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:
##< ;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
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.
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.
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!