Bootstrap html encoding specification, bootstraphtml Encoding

Source: Internet
Author: User

Bootstrap html encoding specification, bootstraphtml Encoding
1.1. Syntax

1. Use two spaces to replace tabs-this is the only way to ensure consistent display in all environments.

2. The nested element should be indented once (that is, two spaces ).

3. For attribute definitions, make sure that all double quotation marks are used. Do not use single quotation marks.

4. Do not add a slash to the end of the self-closing element-this is optional in the HTML5 specification.

5. Do not omit the optional ending tag (for example, </li> or </body> ).

<! DOCTYPE html>

<Html>

<Head>

<Title> Page title </title>

</Head>

<Body>

<H1class = "hello-world"> Hello, world! </H1>

</Body>

</Html>

1.2. HTML5 doctype

Add a standard mode statement to the first line of each HTML page to ensure consistent display in each browser.

<! DOCTYPE html>

<Html>

<Head>

</Head>

</Html>

1.3. Language attributes

According to HTML5 specifications:

We strongly recommend that you specify the lang attribute for the html root element 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.

<Htmllang = "zh-CN">

<! --... -->

</Html>

1.4. IE compatibility mode

IE allows you to use a specific <meta> label 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.

<Metahttp-equiv = "X-UA-Compatible" content = "IE = Edge">

1.5. 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 ).

<Head>

<Metacharset = "UTF-8">

</Head>

1.6. Introduce CSS and JavaScript files

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

<! -- External CSS -->

<Linkrel = "stylesheet" href = "code-guide.css">

 

<! -- In-document CSS -->

<Style>

/*...*/

</Style>

 

<! -- JavaScript -->

<Script src = "code-guide.js"> </script>

1.7. Practical Use is 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.

1.8. attribute order

HTML attributes should be arranged in sequence as follows to ensure the code is easy to understand.

Class

Id, name

Data -*

Src, for, type, href

Title, alt

Aria-*, role

Class is used to identify highly reusable components, so it should be placed first. Id is used to identify a specific component and should be used with caution (for example, bookmarks in the page), so it is placed in the second place.

<Aclass = "..." id = "..." data-modal = "toggle" href = "#">

Example link

</A>

 

<Inputclass = "form-control" type = "text">

 

1.9. boolean attributes

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

If the Boolean attribute of an element has a value, it is true. If there is no value, it is false.

If an attribute exists, its value must be an empty string or a standard name of the [...] attribute, and do not add a blank character.

In short, there is no need to assign values.

<Inputtype = "text" disabled>

 

<Inputtype = "checkbox" value = "1" checked>

 

<Select>

<Optionvalue = "1" selected> 1 </option>

</Select>

1.10. Reduce the number of labels

Avoid unnecessary parent elements when writing HTML code. Most of the time, this requires iteration and refactoring. See the following case:

<! -- Not so great -->

<Spanclass = "avatar">

</Span>

 

<! -- Better -->

1.11. Tag generated by JavaScript

Tags generated by JavaScript make the content difficult to search, edit, and reduce performance. Avoid it if possible.

 

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.