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.
-
Mixing upper and lower case style is very bad.
- Developers usually use lowercase (similar to XHTML).
- The lowercase style looks more refreshing.
- Lowercase letters are easy to write.
Not recommended:
##< ;p>This is a paragraph.
Very bad:
This is a paragraph.
##Recommended:
This is a paragraph.
#Close all HTML elements
elements), but we recommend adding a closing tag to each element.
Not recommended:
##This is a paragraph.
This is a paragraph.
Recommendation:
##This is a paragraph.
This is a paragraph.
Close empty HTML elements
In HTML5, empty HTML elements do not have to be closed:
We can write like this:You can also write like this:
It's good to use this style if you expect XML software to use your page.The slash (/) is required in XHTML and XML.
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 usually use lowercase (similar to XHTML).
The lowercase style looks more refreshing.
Lowercase letters are easy to write.
Not recommended:
#