Common Html development habits (2): html development habits

Source: Internet
Author: User

Common Html development habits (2): html development habits

Common Html development habits:

Introduce CSS and JS

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

HTML5 standard link
• Use link
• Use style
• Use script

<!-- External CSS --><link rel="stylesheet" href="code_guide.css"><!-- In-document CSS --><style>    ...</style><!-- External JS --><script src="code_guide.js"></script><!-- In-document JS --><script>    ...</script>

Attribute order

Attributes should appear in a specific order to ensure ease of use;
• Class
• Id
• Name
• Data -*
• Src, for, type, href, value, max-length, max, min, pattern
• Placeholder, title, alt
• Aria-*, role
• Required, readonly, disabled

Class is designed for highly reusable components, so it should be in the first place;

Id is more specific and should be used as little as possible, so it is placed in the second place.

<a class="..." id="..." data-modal="toggle" href="#">Example link</a><input class="form-control" type="text">

Boolean attribute

A boolean attribute is an attribute that does not need to be declared. XHTML requires each attribute to declare a value, but HTML5 does not;

For more information, see WhatWG section on boolean attributes:

The existence of a boolean attribute indicates that the value is true, and the existence of a boolean attribute indicates that the value is false.

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

JS generate tags

Generating tags in JS files makes the content more difficult to search, more difficult to edit, and worse performance. Avoid this situation as much as possible.

Reduce the number of labels

Avoid unnecessary parent nodes when writing HTML code;

Most of the time, You Need To iterate and refactor to make HTML less.

<!-- Not well --><span class="avatar">    </span><!-- Better -->

Previous Article: naming conventions for front-end development'
Next article: common habits of Html development (1)

I hope to help beginners and take notes at the same time. Thank you!
More follow Fu Yi Fang technology blog: http://blog.csdn.net/fuyifang
Or scan the QR code on your mobile phone to view more blog posts:

Copyright statement: This article is the original author of the blog, not allowed by the blog can not be reproduced, more attention to pay the technical blog: http://blog.csdn.net/fuyifang

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.