web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

First, the only law of

No matter how many people participate in the same project, we must ensure that every line of code written like a unique individual.

Two, HTML

2.1 Syntax

(1) with a space instead of two tabs (tab) - This is the only guaranteed method of obtaining consistent exhibited under all circumstances.

(2) a nested elements should be indented (i.e., two spaces).

(3) to define properties make sure that all double quotes, not to use single quotes.

(4) Do not self-closing tail (self-closing) elements add a slash - HTML5 specification clearly stated that this is optional.

(5) Do not omit optional end tag (closing tag) (e.g., </ li> or </ body>).

2.2 Example

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Three, HTML5 doctype

To add standard mode (standard mode) statements of each of the first line of HTML pages, this can ensure that you have a consistent show in every browser.

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

web前端开发学习Q-q-u-n: 784-783-012 ,分享开发工具,零基础,进阶视频教程,希望新手少走弯路

Fourth, the language attribute

According to the HTML5 specification:

It is strongly recommended to specify html lang attribute to the root element, so as to set the correct language for the document. This will help determine the pronunciation of speech synthesis tool which they should be used, the translation tools will help determine the rules to be observed by its translation and so on.

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Five, IE compatibility mode

IE IE version supports determined draw current page that should be used by a specific <meta> tag. Unless there is a strong special needs, it would be best is set to edge mode, thereby notifying the IE using the latest models it supports.

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Sixth, the character encoding

By explicitly declare the character encoding, you can ensure that your browser quickly and easily judge rendering the page content. The benefit of this is to avoid the use of character entity tag (character entity) in HTML, so all consistent with the document encoding (generally use UTF-8 encoding).

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Seven, the introduction of CSS and JavaScript files

The HTML5 specification, specify the type generally not required when introduced CSS and JavaScript files, because text / css and text / javascript are their default values.

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Eight practical is king

Try to follow HTML standards and semantics, but not at the expense of practicality for the price. As far as possible at all times with minimal labels and maintain a minimum of complexity.

Nine, attribute order

9.1 descending

HTML attributes should be arranged sequentially in the order given below, to ensure legibility.

(1)class

(2)id, name

(3)data-*

(4)src, for, type, href, value

(5)title, alt

(6)role, aria-*

9.2 Example

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

9.3 Description

class for identifying highly reusable components, and should therefore be at the top. id used to identify particular components, it should be used with caution (e.g., a bookmark in the page), so the second row.

X. Boolean (boolean) type attribute

Note 10.1

(1) Boolean attribute can not be assigned at the time of declaration. XHTML specifications give a value, but the HTML5 specification is not required.

Boolean property (2) If there is an element of value, that is true, if no value is false.

(3) If the property is present, its value must be the empty string or [...] canonical name property, and do not add whitespace in end to end.
Simply put, no assignment.

10.2 Example

web front-end entry to the real: the preparation of flexible, stable, standardized high-quality HTML code

Eleven, reducing the number of tags

When writing HTML code, try to avoid unnecessary parent element. In many cases, this requires an iterative and reconstruction to achieve.

Twelve, to reduce the generation of JavaScript tags

JavaScript generated by the tag so that content becomes difficult to find, edit, and degrade performance. Try to avoid to avoid.

Guess you like

Origin blog.51cto.com/14592820/2459098