Home  >  Article  >  Web Front-end  >  HTML5 standard learning-detailed explanation of document structure

HTML5 standard learning-detailed explanation of document structure

黄舟
黄舟Original
2017-03-27 15:34:491624browse

Speaking of the structure of HTML, many people can explain it clearly. Generally speaking, the answer may be like this:

A DOCTYPE, an html, which contains head and body elements.

Of course this cannot be said to be incorrect, but if you ask what a minimum HTML source file must contain, I am afraid that few people can answer it correctly.

Let’s answer this question first. The content required for a simplest HTML5 source code file is as follows:

<!DOCTYPE html>

Yes, that’s it, one character is not much, one There are a lot of characters. Except for the case, which can be changed at will, no other content can be changed.

So what are the rules that cause a simplest source code file to have a doctype statement? According to the standard, an HTML document consists of the following content (strictly in order):

  1. A BOM tag, and this BOM tag must be U+FEFF.

  2. 0-n spaces or comments.

  3. DOCTYPE statement.

  4. 0-n spaces or comments.

  5. An HTML element.

  6. 0-n spaces or comments.

There are some differences from HTML4 here. The simplest source code file of an HTML4 is like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                      "http://www.w3.org/TR/html4/loose.dtd">
<title>这里是标题</title>

The difference between the two is obvious:

  • HTML5 changes DOCTYPE to a simpler 8b05045a5be5764f313ed5b9168a17e6, which is already well known.

  • There is an additional b2386ffb911b14667cb8f0f91ea547a7 tag in HTML4.

The key point here is the b2386ffb911b14667cb8f0f91ea547a7 tag. Regarding this tag, the HTML4.01 standard says this:

Every HTML document must have a TITLE element in the HEAD section.

That is to say, HTML4 requires that the b2386ffb911b14667cb8f0f91ea547a7 tag must exist.

In the HTML5 standard, it says this:

There must be no more than one title element per document.

HTML5 only sets an upper limit on the number of b2386ffb911b14667cb8f0f91ea547a7 tags, but does not specify a lower limit. In other words, a document without b2386ffb911b14667cb8f0f91ea547a7 is considered a legal document. .

For DOCTYPE, there are 6 types of DOCTYPE set in HTML4, and DOCTYPE is divided into 3 types in HTML5. This will be explained in detail in subsequent chapters.

Let’s go back and look at the document composition. Apart from elements that don’t make much sense, the composed list also indicates that there is an HTML element, but there is no such thing in the simplest source code. This is because in the HTML specification, there has always been the concept of "implicit tags". Regarding implicit tags, it can be roughly explained as follows:

Some elements, when certain prerequisites are met, Its start tag or end tag can be omitted in the source code. In this case, the omitted tag is called an "implicit tag".

It should be noted that the omission here refers to the omission of in the source code, but in the final DOM tree, this tag exists, so it is called Implicit tag for . Therefore, the simplest source code structure above, after generating the DOM tree, its real structure is like this:

<!DOCTYPE html>

    
    

Finally, let’s summarize some of the specifications in XHTML:

  • Because it is

    XML, so in order to indicate that this is an HTML document, there must be a namespace whose value is www.w3.org/1999/xhtml.

  • Because it is XML, the MIME type cannot be

    text/html, text/xml, application/xml, application/xml+html are better choices.

  • Because it is XML, there must be a root element. The root element is

    100db36a723c770d327fc0aef2ce13b1, which is the beginning and end of 100db36a723c770d327fc0aef2ce13b1 The label cannot be omitted.

  • Because it is XML, as long as all elements have a start tag, they must not have an end tag or be self-closing.

  • Because it is XML, all elements must be strictly case-sensitive, and element names must be lowercase.

Because it is XML, the document has become much stricter, and because it is XML, its readability and standardization have improved a lot. But in the end, we always have to find the best balance between the tolerance of HTML and the standardization of XML. Blindly pursuing extremes is always a mistake.


The above is the detailed content of HTML5 standard learning-detailed explanation of document structure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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