Document type declaration
A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document (for example, a web page) with a document type definition (DTD) (for example, the formal definition of a particular version of HTML 2.0 - 4.0). In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax. The HTML layout engines in modern web browsers perform DOCTYPE "sniffing" or "switching", wherein the DOCTYPE in a document served as text/html determines a layout mode, such as "quirks mode" or "standards mode". The text/html serialization of HTML5, which is not SGML-based, uses the DOCTYPE only for mode selection. Since web browsers are implemented with special-purpose HTML parsers, rather than general-purpose DTD-based parsers, they do not use DTDs and never access them even if a URL is provided. The DOCTYPE is retained in HTML5 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers.
A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document (for example, a web page) with a document type definition (DTD) (for example, the formal definition of a particular version of HTML 2.0 - 4.0). In the serialized form of the document, it manifests as a short string of markup that conforms to a particular syntax. The HTML layout engines in modern web browsers perform DOCTYPE "sniffing" or "switching", wherein the DOCTYPE in a document served as text/html determines a layout mode, such as "quirks mode" or "standards mode". The text/html serialization of HTML5, which is not SGML-based, uses the DOCTYPE only for mode selection. Since web browsers are implemented with special-purpose HTML parsers, rather than general-purpose DTD-based parsers, they do not use DTDs and never access them even if a URL is provided. The DOCTYPE is retained in HTML5 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers. ==Syntax== The general syntax for a document type declaration is: or ===Document type name=== The opening syntax is followed by separating syntax (such as spaces, or (except in XML) comments opened and closed by a doubled ASCII hyphen), followed by a document type name (i.e. the name of the root element that the DTD applies to trees descending from). In XML, the root element that represents the document is the first element in the document. For example, in XHTML, the root element is <html>, being the first element opened (after the doctype declaration) and last closed. Since the syntax for the external identifier and internal subset are both optional, the document type name is the only information which it is mandatory to give in a DOCTYPE declaration. ===Example=== The first line of a World Wide Web page may read as follows: This document type declaration for XHTML includes by reference a DTD, whose public identifier is -//W3C//DTD XHTML 1.0 Transitional//EN and whose system identifier is http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd . An entity resolver may use either identifier for locating the referenced external entity. No internal subset has been indicated in this example or the next ones. The root element is declared to be html and, therefore, it is the first tag to be opened after the end of the doctype declaration in this example and the next ones, too. The HTML tag is not part of the doctype declaration but has been included in the examples for orientation purposes. Transitional DTD allows some older PUBLIC and attributes that have been deprecated: If frames are used, the Frameset DTD must be used instead, like this: ===XHTML 1.0 DTDs=== XHTML's DTDs are also Strict, Transitional and Frameset. XHTML Strict DTD. No deprecated tags are supported and the code must be written correctly according to XML Specification. XHTML Transitional DTD is like the XHTML Strict DTD, but deprecated tags are allowed. XHTML Frameset DTD is the only XHTML DTD that supports Frameset. The DTD is below. ===XHTML 1.1 DTD=== XHTML 1.1 is the most current finalized revision of XHTML, introducing support for XHTML Modularization. XHTML 1.1 has the stringency of XHTML 1.0 Strict. ===XHTML Basic DTDs=== XHTML Basic 1.0 XHTML Basic 1.1 ===HTML5 DTD-less DOCTYPE=== HTML5 uses a DOCTYPE declaration which is very short, due to its lack of references to a DTD in the form of a URL or FPI. All it contains is the tag name of the root element of the document, HTML . In the words of the specification draft itself: , case-insensitively. With the exception of the lack of a URI or the FPI string (the FPI string is treated case sensitively by validators), this format (a case-insensitive match of the string !DOCTYPE HTML ) is the same as found in the syntax of the SGML based HTML 4.01 DOCTYPE . Both in HTML4 and in HTML5, the formal syntax is defined in upper case letters, even if both lower case and mixes of lower case upper case are also treated as valid. In XHTML5 the DOCTYPE must be a case-sensitive match of the string " ". This is because in XHTML syntax all HTML element names are required to be in lower case, including the root element referenced inside the HTML5 DOCTYPE . The DOCTYPE is optional in XHTML5 and may simply be omitted. However, if the markup is to be processed as both XML and HTML, a DOCTYPE should be used. ==See also== Document type definition contains an example RDFa XML schema ==References== ==External links== HTML Doctype overview Recommended DTDs to use in your Web document - an informative (not normative) W3C Quality Assurance publication DOCTYPE grid - another overview table [Last modified 27 November 2006] Quirks mode and transitional mode Box model tweaking
References
No reference rows published for this article.
Cite this article
MLA
"Document type declaration." encyclopegia.org, 2026, https://encyclopegia.org/wiki/document-type-declaration. Accessed 24 November 2026.
Chicago
"Document type declaration." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/document-type-declaration.
APA
encyclopegia.org. (2026). Document type declaration. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/document-type-declaration
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON