Common habits of HTML development (II)

Source: Internet
Author: User

Common habits of HTML development:

Introducing CSS, JS

According to the HTML5 specification, it is usually not necessary to specify the type when introducing CSS and JS, because Text/css and text/javascript are their default values respectively.

HTML5 Canonical Links
? using link
? using style
? using 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 legibility;
? 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;

The ID is more specific and should be used sparingly, so put it in second place.

<a  class  = "..."  id  = data-modal  = "Toggle"  href  = "#" ;  Example Link</a ;  <input  class  = " Form-control " type  =" text ";  <img  src  = alt  = "..."   

Boolean property

The Boolean property refers to a property that does not require a value to be declared, and XHTML requires a value for each property declaration, but HTML5 does not need it;

For more information, refer to WhatWG section on Boolean attributes:

The presence of a Boolean property represents a value of true, and a value of false is not present.

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

JS Generate tags

Creating tags in a JS file makes it harder to find, harder to edit, and less performance. This situation should be avoided as much as possible.

Reduce the number of labels

When you write HTML code, you need to avoid unnecessary parent nodes as much as possible;

Many times, you need to iterate and refactor to make the HTML less.

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

Previous: Front-end development of common naming conventions '
Next: Common habits of HTML development (i)

This article I hope to beginner friends some help at the same time to retain their notes, thank you!
More Attention Fuyi Technology blog: Http://blog.csdn.net/fuyifang
or scan the QR code directly with your phone to see more Posts:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced, more attention Fuyi technology blog: Http://blog.csdn.net/fuyifang

Common habits of HTML development (II)

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.