What is the role of Doctype? The difference between strict mode and promiscuous mode?

First, the role of Doctype in HTML: the
<!DOCTYPE> declaration is called the file type definition (DTD), the purpose of the declaration is to tell the browser the type of the file. Let the browser parser know which specification should be used to parse the document. <!DOCTYPE>The declaration must be on the first line of the HTML document. This is not an HTML tag. DTD (Document Type Definition) is a set of machine-readable rules that define what is allowed and what is not allowed in a particular version of XML or HTML. When parsing a web page, the browser will use these rules to check the validity of the page and take corresponding measures. The browser understands which DTD to use by analyzing the DOCTYPE declaration of the page, and thus knows which version of HTML to use.

Second, the difference between strict mode and promiscuous mode:
first, strict mode (also known as standard mode, Standards mode) and promiscuous mode (Quirk mode) refer to the rendering mode of the browser, to be distinguished from the two styles of Doctype ( Strict (strict) and transitional (transitional), the purpose of transition DOCTYPE is to help developers migrate from the old version to the new version).
严格模式: Also known as standard mode, which means that the browser parses the code according to the W3C standard to render the page
混杂模式: Also known as weird mode or compatible mode, which means that the browser parses the code in its own way, that is, using a more relaxed backward compatibility Displaying the page
Whether the browser uses strict mode or promiscuous mode to render the page is directly related to the DTD (file type definition) in the web page.
For HTML 4.01 documents,
a DOCTYPE that contains strict DTD often causes the page to be rendered in standard mode.
DOCTYPE with excessive DTD and URI also causes the page to be rendered in standard mode.
But excessive DTD without URI will cause the page to be rendered in promiscuous mode.
The absence or incorrect form of DOCTYPE can cause HTML and XHTML documents to be rendered in promiscuous mode.
For HTML5 documents,
HTML5 does not have a DTD, so there is no difference between strict mode and promiscuous mode. HTML5 has a relatively loose syntax, and it has been implemented as backwards as possible. (HTML5 is not strict and mixed)

 

 

Published 203 original articles · praised 8 · 10,000+ views

Guess you like

Origin blog.csdn.net/z591102/article/details/105533271