HTML5 Standard Learning-Document structure

Source: Internet
Author: User

Speaking of the structure of HTML, a lot of people can speak well, generally speaking, the answer may be this:

A doctype, an HTML, with head and body elements inside.

This certainly cannot be said to be incorrect, but if you ask what some of the smallest HTML source files must have, few of you will be able to respond correctly.

To answer this question first, one of the simplest HTML5 source files requires the following:

<!DOCTYPE html>

Yes, in this way, a character is not many, a lot of characters, in addition to the case can be arbitrarily changed, any other content can not be changed.

So what exactly is the rule that leads to a minimalist source file that must have a DOCTYPE declaration? According to the standard, an HTML document consists of the following content (in strict order):

    1. A BOM tag, and this BOM tag must be U+feff.
    2. 0-n a space or comment.
    3. DOCTYPE statement.
    4. 0-n a space or comment.
    5. An HTML element.
    6. 0-n a space or comment.

There are some differences with HTML4, and the most Jianyuan code file for a HTML4 is 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 changed doctype to be simpler <!DOCTYPE html> , and this is already well known.
    • One more tag in the HTML4 <title> .

The focus here is on the label, which <title> is said in the HTML4.01 standard:

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

That is to say, HTML4 requires that <title> the label be present.

And in HTML5 's standard, that's what it says:

There must is no more than one TITLE element per document.

HTML5 only sets the <title> upper limit of the number of labels, but does not specify a lower limit, that is, no <title> document has been considered a legitimate document.

For the DOCTYPE,HTML4 set in 6 kinds of DOCTYPE,HTML5 will be divided into 3 kinds of doctype, this in a later chapter to specify.

Go back and take a look at the composition of the document, except for the element that doesn't make much sense with 0-n spaces or comments , and the list also shows an HTML element, but none of the simplest sources. This is because in the HTML specification, there has always been the concept of "implicit tagging", about implicit tags, it can be explained roughly:

Part of the element, when a specific precondition is met, its start tag or end tag can be omitted in the source code. In this case, the omitted label is called an "implicit label".

It should be noted that the ellipsis here refers to the omission in the source code, and in the final form of the DOM tree, the tag is present, so it is called an implicit label. So the simplest source structure of the above, after generating the DOM tree, its real structure is this:

<!DOCTYPE html>

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

    • Because it is XML, in order to indicate that this is an HTML document, there must be a namespace with a value of http://www.w3.org/1999/xhtml .
    • Because it is XML, MIME type cannot be, and is a text/html text/xml application/xml application/xml+html better choice.
    • Because it is XML, the root element must be the root element, that is , the start and end tags cannot be omitted.
    • Because it is XML, all elements must have a start tag, they cannot have an end tag, or they can be self-closing.
    • Because it is XML, all elements are strictly case-sensitive, and the element name 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 normative of XML, and it is always a mistake to blindly pursue the extreme.

HTML5 Standard Learning-Document structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.