HTML <!DOCTYPE> (Document Type Definition) Tag
The following example shows how to set the character encoding of the document in HTML5:
Example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Title of the document</title>
</head>
<body>
<p>The content of the document</p>
</body>
</html>
Meaning
The <!DOCTYPE> element cannot have a closing tag.
The <!DOCTYPE> element specifies the document type definition corresponding to the document.
There are no attributes or events associated with this element.
Notes:
- The <!DOCTYPE> declaration is NOT case sensitive.
- The <!DOCTYPE> statement should be in the first line of all documents.
- Validation programs might use this element when determining the correctness of an HTML document.
Standard Syntax
<!DOCTYPE RootElement Availability "URI" [declarations]>
Parts of DOCTYPE | Possible Values |
---|---|
RootElement | Specifies the top-level element of the document
HTML - Normal HTML document. |
Availability | Specifies whether the FPI (formal public identifier) is a system resource or open to the public.
PUBLIC - Open to the public. SYSTEM - Private system resource. |
URI | The URI of the DTD. For example, "-//W3C//DTD HTML 4.01//EN". |
declarations | Specifies the location or the declaration of entities and elements used to parse the document. For example, "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd". |
Note: The HTML5 document type is recommended. (as shown in the above example)
Browser Support
Standard Attributes
The comment tag does not support any standard attributes.
Event Attributes
The comment tag does not support any event attributes.
Document Types Definition
The following are document type definition lists:
Document type | Declaration |
---|---|
HTML5 | <!DOCTYPE html> |
XHTML 1.1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
XHTML 1.1 Strict | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
XHTML 1.1 Transitional | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
XHTML 1.1 Frameset | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> |
XHTML 1.0 Strict | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
XHTML 1.0 Transitional | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
XHTML 1.0 Frameset | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> |
HTML 4.01 Strict | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
HTML 4.01 Transitional | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
HTML 4.01 Frameset | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> |
HTML 3.2 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
HTML 2.0 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
More Examples
The following example shows how to set the character encoding of the document in document types other than HTML5:
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title of the document</title>
</head>
<body>
<p>The content of the document</p>
</body>
</html>