[Specification] Front-end encoding specification-html specification, standard front-end encoding html

Source: Internet
Author: User

[Specification] Front-end encoding specification-html specification, standard front-end encoding html
Document Type

Html5 document type statement is recommended:

<!DOCTYPE html>
Language attributes

According to html5 specifications:

We strongly recommend that youhtmlSpecify the root elementlangAttribute to set the correct language for the document. This will help the speech synthesis tool determine the pronunciation it should adopt and help the translation tool determine the rules it should follow during translation.

The language code table is listed here.

Character encoding

By explicitly declaring the character encoding, the browser can quickly and easily determine the rendering method of the page content. The benefit of doing so is to avoid using character entity tags (character entity) in html, so that all are consistent with document encoding (typically using UTF-8 encoding ).

<meta charset="UTF-8">
IE compatibility mode

IE supportsmetaLabel to determine the IE version used to draw the current page. Unless there are strong special requirements, it is best to setEdge modeTo notify IE to adopt the latest supported mode.

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Omitting the diagonal line of an auto-closed Element

Do not explicitly describe this option by adding a diagonal line to the end of the self-closing element-html5 specification.

Not recommended

<input type="text"/>

Recommendation

<input type="text">
Do not omit the end tag

Do not omit the optional ending tag ).

Not recommended

<ul>    <li></ul>

Recommendation

<ul>    <li></li></ul>
Omitting the type attribute

Omit css and jstypeAttribute. Given the defaulttypeThe value istext/cssAndtext/javascript, SotypeAttributes can be ignored. This is safe and reliable even in older browsers.

Semantic

Use semantic tags, suchh1,pAnd so on.

<! DOCTYPE html> Practical king

Follow html standards and semantics as much as possible, but do not sacrifice practicality. Try to use the least tag at any time and maintain the minimum complexity.

Not recommended

<span class="avatar">    </span>

Recommendation

Structure, representation and behavior Separation

A complete page consists of three parts: structure (html), presentation (css), and behavior (js ). To make them maintained clean and tidy code, we should try to separate them as much as possible.

Strictly ensure the separation of structure, performance, and behavior, and try to avoid too many interactions and connections between the three. That is to say, try to include only structured html in the document and template, move all the presentation code into the style sheet, and move all the action behaviors into the script. In addition, style and script files should be introduced as little as possible in documents and templates to minimize the connections between them.

Clear layering means:

  • No more than one or two style sheets are used
  • Merge scripts as much as possible
  • Do not use embedded style (<style>.no-good {}</style>)
  • Do not use the inline style (<Hr> lower case

    Html tags and attributes (including Custom Attributes) are lowercase letters. Do not use uppercase letters.

    Bind data

    To bind some data to tags, use the Custom Attributes of html5.data-*To bind relevant data.

    <H1 data-age = "20"> JOHN Boolean attribute

    Boolean attributes can be declared without value assignment. The xhtml specification must be assigned a value, but the html5 specification is not required.

    <input type="text" disabled><input type="checkbox" value="1" checked><select>    <option value="1" selected>1</option>    <option value="2"></option></select>
    Html quotation marks

    Use double quotation marks instead of single quotation marks for the html attribute.

    References
    • Web Styleguide-Style guide to harmonize HTML, Javascript and CSS/Sass coding style
    • Http://www.css88.com/archives/5364

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.