Free HTML5 serial came the "HTML5 Web Development Example" serial (c) DOCTYPE and character set

Source: Internet
Author: User

In 2.1.2, by comparing the old and new DOCTYPE, readers can clearly see HTML 5 's efforts to streamline the old structure. DOCTYPE is used primarily in XML as a description of the elements, attributes, and permutations that XML allows to use. At first, HTML drew on the use of DOCTYPE in XML, and gave new usages, such as the well-known standard mode of triggering a browser. If the DOCTYPE is not set when a page is made, the browser will be processed in a weird mode state (i.e. quirks mode), which differs greatly from the standard mode in box model, style, layout, etc. As a result, DOCTYPE is an integral part of making a page.

In the previous version of the HTML 4 standard, DOCTYPE was divided into 3 modes:

    • Strict mode, that is strictly follow the model of the standard, code format is as follows:
    • 1 " -//W3C//DTD html4.01//en " " HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD ">  

    • The transition mode, which contains the content of the standard, can also use tags that are not recommended by the user, such as font, B, etc., and can not use the frame element (that is, the frameset element), the code format is as follows:

1 " -//w3c//dtd HTML4.01 transitional//en "" HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD "
    • Frame mode, you can use the frame element, the other is the same as the transition mode, the code format is as follows:

1 " -//w3c//dtd HTML4.01 frameset//en " " HTTP://WWW.W3.ORG/TR/HTML4/FRAMESET.DTD "

Hint: The old HTML about the DOCTYPE standard, readers can see the official document description, Web address: http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#h-7.2. Although the previous version of the HTML to doctype, but the real situation is that the browser will do its best to render the corresponding page, even if there may be some non-conforming to the pattern, the only thing is that the browser will display some error warning in the console, this is often said that the browser fault tolerance, It is a compromise between the market and the user.

The story to the HTML 5,W3C will doctype eliminate the original chicken's declarative way, simplified to the following format:

<! DOCTYPE html>  

For the vast majority of developers, this is the only way to meet the daily development use, but if you want to consider the future compatibility and extension of a series of issues, but also need to understand the new development of DOCTYPE new regulations, mainly divided into 3 categories:

    • Normal mode, i.e. <! DOCTYPE html>
    • Deprecated mode, sounds unintelligible, in fact, refers to the past mode of compatibility mode, but HTML5 deprecated the previous transition mode and frame mode, eventually left 6 writing format, the code is as follows:
" -//W3C//DTD html4.0//en ">
    1. <! DOCTYPE HTML PUBLIC "-//w3c//dtd html4.0//en" "Http://www.w3.org/TR/REC-html40/strict.dtd">
    2. <! DOCTYPE HTML PUBLIC "-//w3c//dtd html4.01//en">
    3. <! DOCTYPE HTML PUBLIC "-//w3c//dtd html4.01//en" "Http://www.w3.org/TR/html4/strict.dtd">
    4. <! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML1.0 strict//en"
    5. "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    6. <! DOCTYPE HTML PUBLIC "-//w3c//dtd xhtml1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    • Legacy compatibility mode, a compatible way of failing to verify rules in the past, the syntax format is as follows:

    1. <!doctype HTML System "About:legacy-compat">

Through the understanding of browser doctype, readers can be familiar with the mode of browser trigger, but in general development, only need to use <! Doctypehtml> This kind of normal mode.

Tip: The latest 3 modes of HTML 5 can be viewed in the link http://dev.w3.org/html5/markup/syntax.html#doctype-syntax.

The so-called character is a general term for all kinds of words and symbols, covering all countries ' characters, punctuation marks, graphic symbols and numbers. A character set is a collection of multiple characters, commonly used in character sets: ASCII, GB2312, Unicode, ISO, and so on. Scientists need to encode characters so that computers can recognize and store a variety of text in order for computers to handle a variety of character sets accurately.

Before the advent of HTML 5, the browser will confirm the encoding format of the page in 3 ways, in the following order of precedence:

    • Gets the value that corresponds to the content-type character in the HTTP request header.
    • Using the META tag Declaration, the syntax format is as follows:
<meta http-equiv="content-type"content="text/html; Charset=utf-8"
    • The outer chain resource uses the CharSet attribute to declare the encoding format, as in the script tag , using the following syntax format:
<script type="text/javascript"src="myscripts.js " charset="UTF-8"></script>

After the advent of HTML 5, a lot of simplification was made to the use of character sets, which can be declared using the following syntax:

<meta charset="utf-8">

For the daily use of web development, combined with the use of HTML 5 character set, the author gives the following suggestions:

    • The highest priority is to specify the encoding using the HTTP request header.
    • Unified full-site character set encoding, HTML 5 recommended UTF-8 character set.
    • Use the META tag to confirm the character set encoding and place it wherever possible in the first child element of an HTML tag.
    • Third-party referenced scripts, when the character encoding is not confirmed, plus the CharSet property to set the encoding format.

Study HTML5 The best book is "HTML5 Web development Example of the detailed", using code learning case study, can be more interesting than reading text!!! A book to fix HTML5, starting from now.

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.