1. Doctype definition

A generic markup language document type declaration that basically tells the standard Generic Markup Language parser what document type definition (DTD) to use to parse a document. (Doctype is placed in the first line of the HTML file, but it is not a tag and needs to be written before the HTML.)

You can also choose a simple memory:

declaration is at the beginning of the document, before the < HTML > tag. Tells the browser’s parser what document type specification to use to parse the document.

2. The DTD defined

Abbreviation for Document Type Definition.

The validity of AN XML document is guaranteed by defining rules for elements, attributes, tags, and entities in the document and their relationships with each other.

You can also choose a simple memory:

Document Type definitions define what is allowed and what is not allowed in a particular version of XML or HTML, and the browser checks the validity of the page and takes action against these rules when rendering and parsing the page.

DTD type

(1) Strict: structures that cannot contain formatting or presentation, and elements that are deprecated (e.g. font).

For example, Html4.01 and XHTML1.0 are strict types

<! PUBLIC DOCTYPE HTML "- 4.01 / / / / / / W3C DTD HTML EN" "http://www.w3.org/TR/html4/strict.dtd" >Copy the code
<! PUBLIC DOCTYPE HTML "- / / / DTD/W3C XHTML 1.0 Strict / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >Copy the code

(2) Transitional: A structure can contain format tags or CSS, but can still use obsolete elements.

Such as Html4.01 and XHTML1.0 transition

<! PUBLIC DOCTYPE HTML "- / / / / W3C DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd" >Copy the code
<! PUBLIC DOCTYPE HTML "- / / / / W3C DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >Copy the code

(3) Frame (frameset) type: You can use frame technology to achieve multiple web pages in a browser window.

For example, Html4.01 and XHTML1.0 frames.

<! PUBLIC DOCTYPE HTML "- / / / / W3C Frameset DTD HTML 4.01 / / EN" "http://www.w3.org/TR/html4/frameset.dtd" >Copy the code
<! PUBLIC DOCTYPE HTML "- / / / / W3C DTD XHTML 1.0 Frameset / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd" >Copy the code

The above are the three types of DTD. When we use HTML5, we only write this sentence at the beginning, and the browser can parse it. The reason is: HTML5 is not based on SGML, so it does not need to refer to DTD, but it needs DOCTYPE to regulate the behavior of the browser, so that the browser can parse and render the page according to the W3C standard. HTML4.01 and XHTML1.0 are based on SGML, so you need to refer to a DTD to tell the browser which DTD to use to parse the document.

Strict mode and promiscuous mode

Strict mode: Also known as standard mode, the browser parses code according to W3C standards.

Promiscuous mode: Also known as weird mode or compatible mode, this is when the browser parses the code in its own way.

How to tell the difference: Whether the browser parses in strict or promiscuous mode is directly related to the DTD in the web page.

If a document contains a strict DOCTYPE, it will generally be rendered in strict mode. (Strict DTD – Strict schema)

Doctypes that contain a transition DTD and URI are also rendered in strict mode, but having a transition DTD without a URI (uniform resource identifier, which is the last address declared) results in pages being rendered in promiscuous mode. (Transitional DTD with URIs – strict schema; Transitional DTD without URIs — Promiscuous mode)

A DOCTYPE that does not exist or is not in the correct form can cause the document to be rendered in promiscuous mode. (DTD does not exist or is incorrectly formatted — promiscuous mode)

HTML5 does not have a DTD, so there is no distinction between strict schema and promiscuous schema. HTML5 has a relatively loose syntax and is implemented with as much backward compatibility as possible. (HTML5 has no strict and promiscuous distinction.)

Meaning: The reason why strict mode and promiscuous mode exist is closely related to where they come from. If strict mode only exists, then many older sites will be affected. If promiscuous mode only exists, then it will return to the chaos of the browser wars, where each browser has its own resolution mode.

conclusion

  • declaration is at the beginning of the document, before the < HTML > tag. Tells the browser’s parser what document type specification to use to parse the document.

  • Document Type definitions define what is allowed and what is not allowed in a particular version of XML or HTML, and the browser checks the validity of the page and takes action against these rules when rendering and parsing the page.

  • There are three types of DTDS: strict, Transitional, and framework.

  • There are two types of documents that browsers parse, strict and promiscuous, which are closely related to DTDS (strict DTDS), (transitional DTDS with URIs), and (rigid DTDS with urIs). Transition DTDS without URIs — promiscuous mode), (DTDS do not exist or are incorrectly formatted — promiscuous mode), (HTML5 does not distinguish between strict and promiscuous)

  • Why Strict mode and Hybrid mode exist: If there is only strict mode, then many older sites will be affected. If there is only promiscuous mode, then there will be a return to the chaos of the browser wars, where each browser has its own resolution mode.