Why would you use a statement?

Source: Internet
Author: User
Example:

We often see code like this:

<! DOCTYPE html>

Note: you can see a line on the top of the statement about "DOCTYPE" (document type), which tells the browser which specification to use to interpret the specification in this document. You know that without it, the browser uses weird mode when rendering the page (different browsers render the elements differently when they are in weird mode), which results in the same style being seen on different browsers.

Definitions and Usage

<! The doctype> declaration must be the first line in the HTML document before the

<! A doctype> declaration is not an HTML tag; it is a directive that instructs a Web browser about which HTML version the page uses to write.

In HTML 4.01, <! The doctype> declaration references the DTD because HTML 4.01 is based on SGML. The DTD prescribes the rules for markup languages so that the browser can render the content correctly.

HTML5 is not based on SGML, so there is no need to reference DTDs.

tip: always add <! to your HTML document Doctype> declaration so that the browser can learn the document type.

the difference between HTML 4.01 and HTML5

There are three kinds of <! in HTML 4.01 Doctype> statement. Only one of the HTML5:

<! DOCTYPE html>

HTML Elements and document types (Doctype)

See the HTML element table, which lists which document type each element will appear in. Tips and Comments

Note: <! The doctype> declaration does not have an end tag.

Hint:<! Doctype> declarations are insensitive to capitalization.

Tip: Use the authenticator of the html/xhtml to check that you have written a valid document.

Common DOCTYPE Statements HTML 5

<! DOCTYPE html>
HTML 4.01 Strict

The DTD contains all HTML elements and attributes, but does not include display and deprecated elements such as font. Frameset (framesets) is not allowed.

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
HTML 4.01 Transitional

The DTD contains all the HTML elements and attributes, including the displayed and deprecated elements (such as font). Frameset (framesets) is not allowed.

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" 
"HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
HTML 4.01 Frameset

The DTD is equivalent to HTML 4.01 transitional, but allows frameset content.

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 frameset//en" 
"HTTP://WWW.W3.ORG/TR/HTML4/FRAMESET.DTD" >
XHTML 1.0 Strict

The DTD contains all HTML elements and attributes, but does not include display and deprecated elements such as font. Frameset (framesets) is not allowed. tags must be written in well-formed XML.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" 
"HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-STRICT.DTD" >
XHTML 1.0 Transitional

The DTD contains all the HTML elements and attributes, including the displayed and deprecated elements (such as font). Frameset (framesets) is not allowed. tags must be written in well-formed XML.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "
http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">
XHTML 1.0 Frameset

The DTD is equivalent to XHTML 1.0 transitional, but allows frameset content.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 frameset//en" 
"HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-FRAMESET.DTD" >
XHTML 1.1

The DTD is equivalent to the XHTML 1.0 Strict, but allows the addition of models (for example, to provide Ruby support for East Asian languages).

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

Summary declaring a document type (when writing HTML):

<! DOCTYPE html>
advantages of such a declaration:

You can easily write down this doctype without worrying about writing a mistake; it's backwards compatible (because that's what HTML5 's DOCTYPE writes), and modern browsers recognize it.

question: No DTD is specified that will open the strange mode of the browser.

This is a false statement. The right thing to say is that you don't have to define doctype to open weird patterns, which means you just have to define the browser to render the page in strict mode (standard mode) without having to specify a type DTD.


Review:

All browsers have two modes: weird mode and strict mode (others are called standard mode). IE 6 for Windows/mac, Mozilla, Safari and Opera both have implemented these two modes, but IE 6 is always the following version of the bizarre mode.


for both modes, you need to know the following points:

Pages written before normalization are not doctype, so no DOCTYPE pages are rendered in weird mode. Conversely, if a web developer joins a doctype that says he knows what he wants to do, most of the DOCTYPE will open strict mode (Standard mode), The page is also rendered according to the standard. Any new or unknown DOCTYPE will open a strict mode (Standard mode). Each browser has its own way to activate the weird mode.

You can take a look at this list: http://hsivonen.iki.fi/doctype/

Note: You may not need to verify your page based on the doctype you choose, as long as the DOCTYPE tag is present enough to open the strict mode (Standard mode). If you're still skeptical, go to Http://www.quirksmode.org/css/quirksmode.html#link2 to find out what you want to know.

We just need a little piece of JavaScript code to get the answer, which is:

Mode=document.compatmode;

This code can be used to determine whether the current browser is in weird mode or Standard mode, the compatibility of this property is beyond doubt, if you are skeptical, you can view http://www.quirksmode.org/dom/w3c_html.html#t11.

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.