Bootstrap HTML Encoding Specification

Source: Internet
Author: User
Tags closing tag

1.1. Syntax

1. use two spaces instead of tabs (tab) - This is the only way to ensure consistent presentation in all environments.

2. nested elements should be indented one time (that is, two spaces).

3. for the definition of attributes, be sure to use double quotes, never single quotes.

4. do notadd a slash at the end of the self-closing (self-closing) Element - -HTML5 specification This is optional.

5. do not omit the optional end tag (closing tag) (for example,</li> or </body>).

<! DOCTYPE html>

<title>Page title</title>

<body>

src="images/company-logo.png"alt="Company" >

class="Hello-world">Hello, world!

</body>

1.2. HTML5 DOCTYPE

for each HTML the first line of the page adds a standard mode ( Standard mode to ensure consistent representation in each browser.

<! DOCTYPE html>

1.3. Language attributes

according to HTML5 Specification:

highly recommended for HTML The root element specifies Lang property to set the correct language for the document. This will help the speech synthesis tool determine the pronunciation it should use, and help the translation tool determine the rules it should follow when translating.

lang= "ZH-CN" >

<!--...-->

1.4. IE Compatibility mode

IE support through a specific <meta> tags to determine which version of IE should be used to draw the current page . Unless there is a strong special need, it is best to set it to edge mode, which informs IE to use the latest mode it supports.

<meta http-equiv= "X-ua-compatible" content= "Ie=edge" >

1.5. Character encoding

by explicitly declaring character encodings, you can ensure that your browser is quick and easy to determine how the page content is rendered. The advantage of this is that you can avoid using character entity tags (character entity) in HTML, which is all consistent with document encoding (typically UTF-8 encoding).

<metacharset="UTF-8">

1.6. Introducing CSS and JavaScript files

according to HTML5 specification, in the introduction CSS and the JavaScript file, you do not typically need to specify  The Type property, because text/css and text/javascript are their default values, respectively.

<!--External CSS--

<link rel= "stylesheet" href= "Code-guide.css" >

<!--in-document CSS--

<style>

  /* ... */

</style>

<!--JavaScript--

<script src= "Code-guide.js" ></script>

1.7. Practical for the King

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

1.8. Attribute Order

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

<a class= "..." id= "..." data-modal= "Toggle" href= "#" >

Example Link

</a>

<input class= "Form-control" type= "Text" >

src= "..." alt= "..." >

1.9. Boolean Type property

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.

the Boolean property of the element, if it has a value, is true , if there is no value, it is false .

If the attribute exists, its value must be an empty string or [...] the canonical name of the property, and do not end up adding whitespace characters.

Simply put, there is no need to assign a value.

<input type= "Text" Disabled >

<input type= "checkbox" value= "1" checked >

<select>

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

</select>

1.10. Reduce the number of labels

Write HTML code, try to avoid unnecessary parent elements. Many times, this requires iterative and refactoring to implement. Take a look at the following example:

<!--not so great--

<span class= "Avatar" >

src="...">

</span>

<!--Better--

class= "Avatar" src= "..." >

1.11. JavaScript-Generated tags

through JavaScript The resulting label makes the content difficult to find, edit, and degrade performance. Avoid as much as you can avoid.

Bootstrap HTML Encoding Specification

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.