HTML5 coding standards
HTML coding conventions
Many web developers know little about HTML coding conventions.
Between 2000 and 2010, many web developers converted from HTML to XHTML.
Using XHTML developers have gradually developed better HTML writing standards.
For HTML5, we should form better code standards. The following provides several standard suggestions.
Use the correct document type
The document type declaration is located on the first line of the HTML document:
If you want to use lowercase like other tags, you can use the following code:
Use lowercase element names
HTML5 Element names can use uppercase and lowercase letters.
Recommended to use lowercase letters:
Mixing upper and lower case style is very bad.
Developers typically use lowercase (similar to XHTML).
The lowercase style looks more refreshing.
Lowercase letters are easy to write.
Not recommended:
这是一个段落。
Very bad:
这是一个段落。
Recommended:
这是一个段落。
Closing all HTML elements
In HTML5, you don't have to close all elements (such as
elements), but we recommend adding a closing tag to each element.
Not recommended:
这是一个段落。
这是一个段落。
Recommended:
这是一个段落。
这是一个段落。
Close empty HTML elements
In HTML5, empty HTML elements do not have to be closed:
We can write like this:
We can also write like this:
In XHTML The slash (/) is required in XML.
It's good to use this style if you expect XML software to use your page.
Use lowercase attribute names
HTML5 attribute names allow the use of uppercase and lowercase letters.
We recommend using lowercase letters for attribute names:
It is a very bad habit to use uppercase letters at the same time.
Developers typically use lowercase (similar to XHTML).
The lowercase style looks more refreshing.
Lowercase letters are easy to write.
Not recommended: