JS Magic Hall: DocType The basics we should know

Source: Internet
Author: User

First, preface

What is DOCTYPE? In fact, we have been using it, but seldom stop to see what it is and what it does to the web. This article will discuss with you the obscure doctype!

Second, what is DOCTYPE

The DOCTYPE or DTD is declared in the first line of the document, before

Its declaration format is as follows:

    < ! DOCTYPE① html② public ③ "Common identifier"④ "system identifier"⑤>

①. Dotype Fixed starting part

②. Declaring documents with HTML tags as root tags

③. Public is used to indicate that Part IV is a common identifier

④. Public identifiers

⑤. System identifiers

Iii. Types of DOCTYPE

There are three types of doctype (Strict, Transitional, and frameset). Strict is the most stringent type, requiring that the document content be completely detached from the data, and that no representation attributes (such as width, etc.) are allowed in the HTML tag; the transitional is a very loose DTD, Allows you to continue to use HTML4.01 tags, and the data and styles do not need to be completely detached; The Frameset table document uses the framework.

Take XHTML as an example:

  Strict

" -//W3C//DTD XHTML 1.0 strict//en " " HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-STRICT.DTD ">

  Transitional

" -//W3C//DTD XHTML 1.0 transitional//en " " HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD ">

  Frameset

" -//W3C//DTD XHTML 1.0 frameset//en " " HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-FRAMESET.DTD ">

Iv. practical uses of DOCTYPE

In addition to the above uses, DOCTYPE also has a very important purpose, that is to trigger the document mode switch. In the absence of a valid DOCTYPE, the browser will parse and render the document in a weird mode, otherwise it will use standard mode to process the document. Of course, the specific situation is not so simple, specific can see "JS Magic Hall: Browser mode and document mode How to play?" 》

So the different DTD will make the browser switch to which state, please refer to:

Note: Due to the fact that in the actual use process, the most important function of discovering DOCTYPE is to switch the document mode, so the HTML5 specification simplifies the DOCTYPE declaration format to <! DOCTYPE Html> So we'll just write this simplified version in a few minutes. ("Theoretical guidance practice, practical verification of truth" was once again verified)

V. Summary

See so much, in fact, only in the future when the development of remember in the first line of the document plus <! DOCTYPE html> is OK, simple, right?

Vi. references, thank you!

Correct use of doctype:http://www.cnblogs.com/shishm/archive/2012/02/29/2373080.html

Activating Browser Modes with doctype:https://hsivonen.fi/doctype/("front-end translator: activating Browser Modes with Doctype")

Respect the original, reprint please indicate from: http://www.cnblogs.com/fsjohnhuang/p/3821463.html ^_^ Fat Boy John

  

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.