Advertisement

HTML <! DOCTYPE> tag

Examples

<!DOCTYPE html>
<html>
<head>
<title>文档的标题</title>
</head>

<body>
文档的内容......
</body>

</html>

Try it yourself

Browser Support

IE Firefox Chrome Safari Opera

All browsers support <! DOCTYPE> declaration.

Definition and Usage

<! DOCTYPE> declaration must be the first line of HTML documents located in <html> tag before.

<! DOCTYPE> declaration is not an HTML tag; it is an indication of web browser to use on which page HTML version written instructions.

In HTML 4.01, <! DOCTYPE> declaration referenced DTD, since HTML 4.01 based on SGML. DTD specifies the rules for markup language, so that the browser can properly render content.

HTML5 is not based on SGML, so no reference DTD.

Tip: Always add a statement to the HTML document, so that the browser can be informed of the type of document <DOCTYPE!>.

Differences between HTML 4.01 and HTML5

There are three <! DOCTYPE> declaration in HTML 4.01. In HTML5 there is only one:

<!DOCTYPE html>

HTML elements and the document type (Doctype)

See this HTML element list that lists each element which will appear in the document type .

Tips and Notes

NOTE: <! DOCTYPE> declaration no end tag.

Tip: <! DOCTYPE> declaration is not case sensitive.

Tip: Use the W3C validator to check if you write valid HTML / XHTML document!

Common DOCTYPE declaration

HTML 5

<!DOCTYPE html>

HTML 4.01 Strict

The DTD contains all HTML elements and attributes, but does not include illustrative and deprecated elements (like font). Allowed frameset (Framesets).

<!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 HTML elements and attributes, including the display of and deprecated elements (like font). Allowed frameset (Framesets).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

HTML 4.01 Frameset

This is equivalent to the DTD 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 illustrative and deprecated elements (like font). Allowed frameset (Framesets). Must be written correctly formatted XML tags.

<!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 HTML elements and attributes, including the display of and deprecated elements (like font). Allowed frameset (Framesets). Must be written correctly formatted XML tags.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XHTML 1.0 Frameset

This is equivalent to the DTD 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

This is equivalent to the DTD XHTML 1.0 Strict, but allows you to add model (for example to provide ruby ​​support for East Asian language family).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">