Table of Contents
HTML4 DOCTYPE
<!DOCTYPE html>
Home Web Front-end H5 Tutorial HTML5 standards learning-DOCTYPE header analysis

HTML5 standards learning-DOCTYPE header analysis

Mar 27, 2017 pm 03:36 PM

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.

HTML4 DOCTYPE

In the HTML4 standard, DOCTYPE is included in the chapter "HTML Version Information". In this chapter, the standard specifies 3 types of DOCTYPE:

  • ##Strict mode:

    #.

    #Transitional mode:
  • .

    Frame mode:
  • .

    In the HTML4 standard, the dtd file corresponding to each DOCTYPE is specified by a legal URL and can be downloaded through the Internet. The browser can obtain the specific content of the dtd according to the URL and parse the document according to the provisions of the content.
Reality is different

HTML4, like XML, is a fairly ideal standard. However, 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">
<html>
    <head>
        <title>I&#39;m not a frameset</title>
    </head>
    <body>
        <p>So what?</p>
    </body>
</html>
Copy after login

This document uses a DOCTYPE in frame mode, but its text does not use any

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.

This is the so-called "fault tolerance" of the browser. In fact, no matter what your DOCTYPE is, the browser will parse a document with the greatest compatibility and make the greatest efforts to display the document. Meets developer expectations. This feature of the browser has gradually made the standard setters realize that DOCTYPE does not seem to be very important. Therefore, in

HTML5

, DOCTYPE has undergone a major change...

HTML5's DOCTYPE

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 w3cvalidator

, DOCTYPE seems to only trigger browser compatibility mode. So the standards working group adopted a very practical attitude and tested the simplest DOCTYPE that triggers the standard mode for all courses, and finally came to this conclusion.

But the story will not be that simple. The Standards Working Group is not a rogue who just completes such a simple action and abandons it. In fact, they still conscientiously consider backward compatibility, scalability, etc. In the end, the DOCTYPE chapter used a lot of words to describe the series of things, and got a very detailed result.

In the relevant chapters of the HTML5 reference manual, DOCTYPE is divided into three categories:

Normal DOCTYPE - normal doctype
  • Ordinary DOCTYPE is the simplest form we have seen, that is,
  • . Its real composition is like this:

  • A piece of text , that is,
    , which is case-insensitive.

  1. One or more spaces. For the definition of spaces, please refer to the explanation in Introduction.

  2. charactersHTML, also case-insensitive.

  3. 1 or more spaces.

  4. 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>##&lt ;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN"><code>

  5. #

  6. ##
  7. < ;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  8. ##
  9. 1 or more spaces.
    1. 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.

    2. A piece of text, namely
    , is case-insensitive.
  10. 1 or more spaces.

  11. characters

    HTML
  12. , also case-insensitive.
  13. 1 or more spaces.

  14. characters

    PUBLIC
  15. , case insensitive.
  16. Continue with 1 or more spaces.

  17. A pair of quotation marks or single quotation marks (must match before and after), put a Public ID in the quotation marks.

  18. Optional content:

  19. 1 or more spaces.

  20. End tag, that is,

    >.
  21. Legacy tool DOCTYPE - legacy tool compatible doctype
  22. 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:

  23. For example, this DOCTYPE falls into this category:
  24. < ;!doctype HTML system "about:legacy-compat">

    , basically there is nothing worth changing except the case.

    A piece of text, namely
  25. , is case-insensitive.
  26. 1 or more spaces.

  27. characters

    HTML
  28. , also case-insensitive.
  29. 1 or more spaces.

  30. characters

    SYSTEM
  31. , case insensitive.
  32. Continue with 1 or more spaces.

  33. A pair of quotation marks or single quotation marks (must match before and after), put a text

    about:legacy-compat
  34. in the quotation marks, note that this text is in uppercase and lowercase
  35. Sensitive.

    1 or more spaces.

  36. End tag, that is,

    >.

  37. Realistic details

  38. Regarding the role of DOCTYPE, in real browsing, it only plays the role of triggering the standard mode of the browser. Although according to the standard, in an HTML document, there can be other elements before DOCTYPE, such as a U+FFEF BOM, a few comments , and a little space, but in the current state, it is not so ideal:

    For IE6-9, if there is a comment before DOCTYPE, it will enter Quirks mode.

    • For IE6, if there is an XML declaration before DOCTYPE, it will enter Quirks mode.

    • After I finished writing, I discovered that the problem was all in IE... The issue about DOCTYPE has been entangled at this point. The next chapter mainly talks about the issue of encoding declaration.

    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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

See all articles