HTML5 standard learning-DOCTYPE and html5 standard doctype
The so-called DOCTYPE is initially the concept of XML, that is, using a specific syntax as a metadata to describe the elements that can appear in XML documents, and the composition and nesting rules of each element. You can get a more detailed result in the WIKI.
But in HTML, DOCTYPE has some different effects. One of them is the famous function that triggers the standard browser mode. That is, without DOCTYPE, the browser will enter a strange state called Quirks mode. In this mode, the box model, style parsing, and layout of the browser are all different from those specified in the standard.
It should be noted that the so-called HTML and DOM standards only specify the concepts and behaviors in the standard mode, as mentioned in the document structure, DOCTYPE is an HTML document that cannot be omitted. Therefore, there is no such concept as "Quirks mode. It is precisely because the standard does not set any rules for the Quirks mode. Therefore, different browsers have different processing methods in the Quirks mode, and it is difficult to apply the Quirks mode.
DOCTYPE of HTML4
In the HTML4 standard, DOCTYPE belongs to the Chapter "HTML Version Information. In this chapter, three types of DOCTYPE are specified:
- Strict mode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
.
- Transition mode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
.
- Framework mode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
.
In the HTML4 standard, every dtd file corresponding to DOCTYPE has a valid URL and can be downloaded over the Internet. The browser can obtain the specific content of the dtd Based on the URL and parse the document according to the content.
The reality is different.
HTML4, like XML, is an idealized standard. However, the reality is often not so ideal. Imagine the following HTML document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
This document uses the doctype of the framework mode, but its body does not use any<frame>
Corresponding to the standard HTML structure that should be specified by the strict mode or transition mode. In this case, what can a browser do?
Refuse to render this page? No, browsers do not dare to do this. In the fierce market competition, if some pages cannot be rendered as a result, they can only watch the market share inject into other fields. Therefore, the browser reports a warning at most weakly to protest, but it still needs to properly parse this document and render it correctly.
This is the so-called "Fault Tolerance" of browsers. In fact, no matter what your DOCTYPE is, the browser will parse a document with maximum compatibility, and make the best effort to make this document display in line with developers' expectations. This feature of the browser gradually makes the standard maker realize that DOCTYPE is really not very important. Therefore, in HTML5, DOCTYPE has undergone a major change ......
HTML5 DOCTYPE Now that HTML5 is ready, most people know this change, that is, HTML5 simplifies the DOCTYPE statement.<!DOCTYPE html>
You can.
As mentioned above, in the HTML4 era, standard makers have realized that DOCTYPE is not very helpful for browser rendering, except for reading the boring w3c validators, DOCTYPE seems to only trigger the browser compatibility mode. As a result, the Standards Working Group took a very practical attitude and tested the simplest DOCTYPE that triggers the standard mode for all courses. Finally, this conclusion was drawn.
But the story won't be so simple, and the standard working group is not a rogue who just gets rid of such simple actions. In fact, they are still very responsible for considering a series of things such as backward compatibility and scalability, finally, the DOCTYPE chapter is described in a large amount of text to get a very detailed result.
In the HTML5 reference manual, DOCTYPE is divided into three categories:
-
Normal DOCTYPE-normal doctype
-
Common DOCTYPE is the simplest form we see, that is<!DOCTYPE html>
The real composition is as follows:
-
No longer recommended DOCTYPE-deprecated doctype
-
This is the so-called several doctype in the HTML4 era. Its composition is as follows:
- One or more spaces.
- End mark, that is
>
.
In the standard, the Public ID and System ID have a strict ing relationship. If the specified System ID cannot have a Public ID, the optional content of the above 8th items cannot exist. HTML5 has completely abandoned the transition type and framework-type DOCTYPE in HTML4, and integrated the xhtml doctype declaration to come up with the following six combination methods:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-
Legacy tool DOCTYPE-leagacy tool compatible doctype
-
As the name suggests, it is a DOCTYPE designed to be compatible with the historical heritage of a long time, and there is no way to prove what kind of "tool" will produce this DOCTYPE ...... The components of the legacy tool-type DOCTYPE are as follows:
For example, such DOCTYPE belongs to this class:<!doctype HTML system "about:legacy-compat">
Basically, except for Case sensitivity, There is nothing worth changing.
Details of reality The role of DOCTYPE can only trigger the standard mode of the browser in real browsing. According to the standard, in an HTML document, there can be other elements before DOCTYPE, such as a bom of U + FFEF, several comments, and a little space, but in the current state, this is not ideal:
- For a IE6-9, if a comment exists before DOCTYPE, it enters the Quirks mode.
- For IE6, if an XML Declaration exists before DOCTYPE, it enters the Quirks mode.
I found out that the problem lies in IE again ...... The problem about DOCTYPE is so entangled that the next chapter focuses on coding declaration.