HTML5 standard learning and html5 standard learning
When talking about the structure of HTML, many people can say the first thing. Generally, the answer may be like this:
A doctype and an html with head and body elements.
Of course, this cannot be said to be incorrect. However, if you ask what the smallest HTML source file must have, few people may answer the question correctly.
To answer this question, the simplest HTML5 source code file requires the following content:
<!DOCTYPE html>
Yes. In this case, there are not many characters and many characters. Except the case sensitivity can be changed, nothing else can be changed.
So what exactly are the rules that make a simplest source code file have a doctype declaration? According to the standard, an HTML document consists of the following content (in strict order ):
There are some differences between HTML4 and HTML4. The simplest source code file of HTML4 is as follows:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <title> here is the title </title>
The difference between the two is obvious:
- HTML5 changes DOCTYPE to a simpler
<!DOCTYPE html>
This is well known.
- Added one more parameter in HTML4.
<title>
Label.
The focus here is<title>
Tag. This label is described in the HTML4.01 standard:
Every HTML document must have a TITLE element in the HEAD section.
That is to say, HTML4 requires<title>
The tag must exist.
In HTML5 standards, this is also said:
There must be no more than one title element per document.
Only<title>
The upper limit of the number of tags, but the lower limit is not specified. That is to say, no<title>
Has been considered as a legal document.
For DOCTYPE, six types of DOCTYPE are set in HTML4. In html5. there are three types of DOCTYPE, which will be described in later sections.
Let's take a look at the composition of the document.0-N spaces or comments
In this way, there is not much significance to the element. The list of components also shows that there is an HTML element, but this is not in the simplest source code. This is because the concept of "implicit tag" has always existed in the HTML specification. For implicit tags, it can be roughly explained as follows:
Some elements. When specific prerequisites are met, the start or end tags can be omitted in the source code. In this case, the omitted tag is called "implicit tag ".
Note that the omission here refersOmitted in source codeIn the final DOM tree, this tag exists and is calledImplicitLabel. Therefore, the simplest source code structure is as follows after the DOM tree is generated:
<!DOCTYPE html>
Finally, we will summarize some of the XHTML specifications:
- Because it is XML, in order to indicate that this is an HTML document, there must be a namespace whose value is
http://www.w3.org/1999/xhtml
.
- Because it is XML, the MIME type cannot be
text/html
Now,text/xml
,application/xml
,application/xml+html
They are all good choices.
- Because it is XML, there must be a root element. The root element is
, That isThe start and end labels cannot be omitted.
- Because it is XML, as long as all elements have a start tag, they cannot be closed or closed.
- Because it is XML, all elements must be case-sensitive and the element name must be lower-case.
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 need to find the best balance between HTML's width and XML's standardization, and blindly pursuing extremes is always a mistake.