Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap HTML Coding Standards

Bootstrap HTML Coding Standards

Syntax

Example:







  

    Page title

  

  

    Company

    

Hello, world!

HTML5 doctype

Add a standards mode declaration to the first line of every HTML page to ensure consistent rendering in every browser.

Example:







  

  



Language Attribute

According to the HTML5 specification:

It is strongly recommended to specify the lang attribute on the html root element to set the correct language for the document. This helps speech synthesis tools determine the pronunciation to use and helps translation tools determine the rules to follow when translating, among other things.

Here is a list oflanguage codes.。





  



IE Compatibility Mode

IE supports determining the IE version used to render the current page through a specific tag. Unless there is a strong specific need, it is best to set it to edge mode, thereby telling IE to use the latest mode it supports.





: This method loads the entire file content into memory, so it is not suitable for processing large files

Explicitly declaring the character encoding ensures that the browser can quickly and easily determine how to render the page content. The benefit of doing this is that it avoids using character entities in HTML, keeping everything consistent with the document encoding (typically UTF-8).





  



Including CSS and JavaScript Files

According to the HTML5 specification, you generally do not need to specify the type attribute when including CSS and JavaScript files, because text/css and text/javascript are their default values, respectively.

HTML5 spec links



















Practicality Above All

Try to follow HTML standards and semantics, but not at the expense of practicality. Always use the fewest tags and keep complexity to a minimum.

Attribute Order

HTML attributes should be arranged in the order given below to ensure code readability.

class identifies highly reusable components, so it should come first. id identifies specific components and should be used cautiously (e.g., bookmarks within a page), so it comes second.





  Example link









...

Boolean Attributes

Boolean attributes can be declared without a value. The XHTML specification requires a value, but the HTML5 specification does not.

For more information, see WhatWG section on boolean attributes:

A boolean attribute of an element is true if it has a value and false if it does not.

If both theAlwaysTo assign a value to it, refer to the WhatWG specification:

If the attribute is present, its value must be the empty string or the canonical name of the attribute in [...], with no whitespace at the beginning or end.

In short, you do not need to assign a value.













Reduce the Number of Tags

When writing HTML code, try to avoid redundant parent elements. Often, this requires iteration and refactoring to achieve. See the case below:







  









JavaScript-Generated Tags

Tags generated by JavaScript make content harder to find and edit, and reduce performance. Avoid them whenever possible.