- Adding a standard mode declaration to the first line of each HTML page ensures a consistent representation in every browser.
- Use two spaces instead of tabs (tab)-this is the only way to ensure consistent presentation in all Environments.
- Nested elements should be indented one time (that is, two spaces).
- For the definition of a property, make sure to use double quotes and never use single quotes.
- Do not add a slash at the end of the self-closing (self-closing) element-the HTML5 specification explicitly describes this as Optional.
- Do not omit the optional end tag (closing tag) (for example,
</li> or </body> ).
- In the introduction of CSS and JavaScript files, It is generally not necessary to specify
type properties, because text/css and text/javascript respectively, their default values.
- A Boolean property can be declared without assigning a value. The XHTML specification requires that it be assigned a value, but the HTML5 specification does Not.
1 <!DOCTYPE HTML>2 <HTMLLang= "zh-cn">3 <Head>4 <title>Page Title</title>5 </Head>6 <Body>7 <imgsrc= "images/company-logo.png"alt= "company">8 <H1class= "hello-world">Hello, world!.</H1>9 </Body>Ten </HTML>
HTML attributes should be arranged in the order given below to ensure readability of the Code.
class
id,name
data-*
src, for, type,href
title,alt
aria-*,role
Class is used to identify highly reusable components and should therefore be ranked First. ID is used to identify specific components and should be used with caution (for example, bookmarks within a page), so it is ranked Second.
1 <aclass="..."ID="..."Data-modal= "toggle"href="#">2 Example Link3 </a>4 5 <inputclass= "form-control"type= "text">6 7 <imgsrc="..."alt="...">
1 <inputtype= "text"Disabled>2 3 <inputtype= "checkbox"value= "1"checked>4 5 <Select>6 <optionvalue= "1"selected>1</option>7 </Select>
HTML5 Coding Specification