Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Html !DOCTYPE declaration


May 04, 2021 HTML Reference Manual


Table of contents


HTML <! DOCTYPE

DOCTYPE is a short case of document type (document type).

DOCTYPE is a document type tag, a document type declaration in a standard common tag language that is used in a web design to describe what version of XHTML or HTML you are using.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>

<body>
Document content ...
</body>

</html>

Try it out . . .

Browser support

Html !DOCTYPE declaration Html !DOCTYPE declaration Html !DOCTYPE declaration Html !DOCTYPE declaration Html !DOCTYPE declaration

All major browsers support slt;! DOCTYPE.


Label definition and instructions for use

<! The DOCTYPE is declared to be at the top of the document, before the label.

<! The DOCTYPE declaration is not an HTML tag;

In HTML 4.01, slt;! T he DOCTYPE declaration refers to DTD (document type declaration) because HTML 4.01 is based on SGML (Standard Generalized Markup Language standard common tag language). The DTD specifies rules for the markup language, ensuring that the browser renders the content correctly.

HTML5 is not based on SGML and therefore does not require a reference to DTD.

Tip: Always add a slt;! to your HTML documents! DOCTYPE is declared to ensure that the browser knows the document type in advance.

Tip: More details about DTD are available here: Introduction to DTD!


The difference between HTML 4.01 and HTML5

HTML 4.01 specifies three different types of D OCTYPE's statements are Strict, Transitional, and Frameset, respectively. There is only one type specified in HTML5:

<!DOCTYPE html>

HTML elements and Doctypes

See HTML elements and legitimate Doctype to see which Doctype each HTML element appears in.


Tips and comments

Note: slt;! The DOCTYPE.label does not end the label.

Tip: slt;! DoCTYPE is declared case insensoption.

Tip: Use W3C validation to check if you've written a legitimate HTML/XHTML document with the correct DTD!


Common DOCTYPE declarations

HTML 5

<!DOCTYPE html>

HTML 4.01 Strict

This DTD contains all HTML elements and properties, but does not include appearances or outdated elements such as font. Frame sets are not allowed.

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

HTML 4.01 Transitional

This DTD contains all HTML elements and properties, including ostentats or out-of-date elements such as font. Frame sets are not allowed.

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

HTML 4.01 Frameset

This DTD is the same as HTML 4.01 Transitional, but allows the use of frame set content.

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

XHTML 1.0 Strict

This DTD contains all HTML elements and properties, but does not include appearances or outdated elements such as font. F rame sets are not allowed. Structures must be written in standard-format 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

This DTD contains all HTML elements and properties, including ostentats or out-of-date elements such as font. F rame sets are not allowed. Structures must be written in standard-format 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

This DTD is the same as XHTML 1.0 Transitional, but allows the use of frame set 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 DTD is the same as XHTML 1.0 Strict, but allows you to add modules such as ruby support for East Asian languages.

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

Extended reading: XHTML DTD three file type declarations