fbpx
Wikipedia

Document type declaration

A document type declaration, or DOCTYPE, is an instruction that associates a particular XML or SGML document (for example, a webpage) with a document type definition (DTD) (for example, the formal definition of a particular version of HTML 2.0 - 4.0).[1] 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.[2]

DTDs

Syntax

The general syntax for a document type declaration is:

<!DOCTYPE root-element PUBLIC "/quotedFPI/" "/quotedURI/" [ <!-- internal subset declarations --> ]> 

or

<!DOCTYPE root-element SYSTEM "/quotedURI/" [ <!-- internal subset declarations --> ]> 

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. The keywords SYSTEM and PUBLIC suggest what kind of Document Type Definition (DTD) it is (one that is on a private system or one that is open to the public). If the PUBLIC keyword is chosen, it is followed by a restricted form of "public identifier" called Formal Public Identifier (FPI) enclosed in double quote marks. The public identifier may be followed by a "system identifier" that is likewise double-quoted. For example, the FPI for XHTML 1.1 is "-//W3C//DTD XHTML 1.1//EN" and, there are 3 possible system identifiers available for XHTML 1.1 depending on the needs. One of them is the URI reference "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd". If, instead, the SYSTEM keyword is chosen, only a system identifier is provided. It means that the XML parser must locate the DTD in a system specific fashion, in this case, by means of a URI reference of the DTD enclosed in double quote marks. The last part, surrounded by literal square brackets ([]), is called an internal subset which can be used to add/edit entities or add/edit PUBLIC keyword behaviors.[3] The internal subset is always optional (and sometimes even forbidden within simple SGML profiles, notably those for basic HTML parsers that don't implement a full SGML parser).

In XHTML documents, the doctype declaration must always explicitly specify a system identifier. In SGML-based documents like HTML, on the other hand, the appropriate system identifier may automatically be inferred from the given public identifier. This association might e.g. be performed by means of a catalog file resolving the FPI to a system identifier.[4]

Example

The first line of a World Wide Web page may read as follows:

<!DOCTYPE html PUBLIC  "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="ar" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> 

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.

Common DTDs

Some common DTDs have been put into lists. W3C has produced a list of DTDs commonly used in the web, which contains the "bare" HTML5 DTD, older XHTML/HTML DTDs, DTDs of common embedded XML-based formats like MathML and SVG as well as "compound" documents that combine those formats.[5] Both W3C HTML5 and its corresponding WHATWG version recommend browsers to only accept XHTML DTDs of certain FPIs and to prefer using internal logic over fetching external DTD files. It further specifies an "internal DTD" for XHTML which is merely a list of HTML entity names.[6]: §13.2 

HTML 4.01 DTDs

Strict DTD does not allow presentational markup with the argument that Cascading Style Sheets should be used for that instead. This is how the Strict DTD looks:

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

Transitional DTD allows some older PUBLIC and attributes that have been deprecated:

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

If frames are used, the Frameset DTD must be used instead, like this:

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

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.

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

XHTML Transitional DTD is like the XHTML Strict DTD, but deprecated tags are allowed.

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

XHTML Frameset DTD is the only XHTML DTD that supports Frameset. The DTD is below.

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

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.

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

XHTML Basic DTDs

XHTML Basic 1.0

<!DOCTYPE html PUBLIC  "-//W3C//DTD XHTML Basic 1.0//EN"  "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> 

XHTML Basic 1.1

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

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.[7] In the words of the specification draft itself:

In other words, <!DOCTYPE html>, 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 "<!DOCTYPE html>". 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.[8] However, if the markup is to be processed as both XML and HTML, a DOCTYPE should be used.[9]

See also

References

  1. ^ HTML2 HTML3 HTML4
  2. ^ "The HTML syntax ― HTML5". Retrieved 2011-06-05.
  3. ^ "DOCTYPE Declaration". msdn.microsoft.com.
  4. ^ . Archived from the original on 2011-08-14. Retrieved 2011-09-09.
  5. ^ "W3C QA - Recommended list of Doctype declarations you can use in your Web document". www.w3.org. Retrieved 22 March 2019.
  6. ^ "HTML Standard". html.spec.whatwg.org. Retrieved 22 March 2019.
  7. ^ "The HTML syntax ― HTML5". Web Hypertext Application Technology Working Group. Retrieved 2011-06-05. 3. A string that is an ASCII case-insensitive match for the string "DOCTYPE". 5. A string that is an ASCII case-insensitive match for the string "HTML".
  8. ^ . Web Hypertext Application Technology Working Group. Archived from the original on 2012-06-18. Retrieved 2009-09-01.
  9. ^ "Polyglot Markup: HTML-Compatible XHTML Documents". World Wide Web Consortium. Retrieved 2012-01-17.

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

document, type, declaration, document, type, declaration, doctype, instruction, that, associates, particular, sgml, document, example, webpage, with, document, type, definition, example, formal, definition, particular, version, html, serialized, form, document. A document type declaration or DOCTYPE is an instruction that associates a particular XML or SGML document for example a webpage with a document type definition DTD for example the formal definition of a particular version of HTML 2 0 4 0 1 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 2 Contents 1 DTDs 1 1 Syntax 1 2 Example 2 Common DTDs 2 1 HTML 4 01 DTDs 2 2 XHTML 1 0 DTDs 2 3 XHTML 1 1 DTD 2 4 XHTML Basic DTDs 2 5 HTML5 DTD less DOCTYPE 3 See also 4 References 5 External linksDTDs EditSyntax Edit The general syntax for a document type declaration is lt DOCTYPE root element PUBLIC quotedFPI quotedURI lt internal subset declarations gt gt or lt DOCTYPE root element SYSTEM quotedURI lt internal subset declarations gt gt In XML the root element that represents the document is the first element in the document For example in XHTML the root element is lt html gt being the first element opened after the doctype declaration and last closed The keywords SYSTEM and PUBLIC suggest what kind of Document Type Definition DTD it is one that is on a private system or one that is open to the public If the PUBLIC keyword is chosen it is followed by a restricted form of public identifier called Formal Public Identifier FPI enclosed in double quote marks The public identifier may be followed by a system identifier that is likewise double quoted For example the FPI for XHTML 1 1 is W3C DTD XHTML 1 1 EN and there are 3 possible system identifiers available for XHTML 1 1 depending on the needs One of them is the URI reference http www w3 org TR xhtml1 DTD xhtml1 transitional dtd If instead the SYSTEM keyword is chosen only a system identifier is provided It means that the XML parser must locate the DTD in a system specific fashion in this case by means of a URI reference of the DTD enclosed in double quote marks The last part surrounded by literal square brackets is called an internal subset which can be used to add edit entities or add edit PUBLIC keyword behaviors 3 The internal subset is always optional and sometimes even forbidden within simple SGML profiles notably those for basic HTML parsers that don t implement a full SGML parser In XHTML documents the doctype declaration must always explicitly specify a system identifier In SGML based documents like HTML on the other hand the appropriate system identifier may automatically be inferred from the given public identifier This association might e g be performed by means of a catalog file resolving the FPI to a system identifier 4 Example Edit The first line of a World Wide Web page may read as follows lt DOCTYPE html PUBLIC W3C DTD XHTML 1 0 Transitional EN http www w3 org TR xhtml1 DTD xhtml1 transitional dtd gt lt html lang ar dir ltr xmlns http www w3 org 1999 xhtml gt 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 Common DTDs EditSome common DTDs have been put into lists W3C has produced a list of DTDs commonly used in the web which contains the bare HTML5 DTD older XHTML HTML DTDs DTDs of common embedded XML based formats like MathML and SVG as well as compound documents that combine those formats 5 Both W3C HTML5 and its corresponding WHATWG version recommend browsers to only accept XHTML DTDs of certain FPIs and to prefer using internal logic over fetching external DTD files It further specifies an internal DTD for XHTML which is merely a list of HTML entity names 6 13 2 HTML 4 01 DTDs Edit Strict DTD does not allow presentational markup with the argument that Cascading Style Sheets should be used for that instead This is how the Strict DTD looks lt DOCTYPE HTML PUBLIC W3C DTD HTML 4 01 EN http www w3 org TR html4 strict dtd gt lt html gt Transitional DTD allows some older PUBLIC and attributes that have been deprecated lt DOCTYPE HTML PUBLIC W3C DTD HTML 4 01 Transitional EN http www w3 org TR html4 loose dtd gt lt html gt If frames are used the Frameset DTD must be used instead like this lt DOCTYPE HTML PUBLIC W3C DTD HTML 4 01 Frameset EN http www w3 org TR html4 frameset dtd gt lt html gt XHTML 1 0 DTDs Edit 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 lt xml version 1 0 encoding UTF 8 gt lt DOCTYPE html PUBLIC W3C DTD XHTML 1 0 Strict EN http www w3 org TR xhtml1 DTD xhtml1 strict dtd gt lt html xmlns http www w3 org 1999 xhtml xml lang en lang en gt XHTML Transitional DTD is like the XHTML Strict DTD but deprecated tags are allowed lt xml version 1 0 encoding UTF 8 gt lt DOCTYPE html PUBLIC W3C DTD XHTML 1 0 Transitional EN http www w3 org TR xhtml1 DTD xhtml1 transitional dtd gt lt html xmlns http www w3 org 1999 xhtml xml lang en lang en gt XHTML Frameset DTD is the only XHTML DTD that supports Frameset The DTD is below lt xml version 1 0 encoding UTF 8 gt lt DOCTYPE html PUBLIC W3C DTD XHTML 1 0 Frameset EN http www w3 org TR xhtml1 DTD xhtml1 frameset dtd gt lt html xmlns http www w3 org 1999 xhtml xml lang en lang en gt XHTML 1 1 DTD Edit 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 lt DOCTYPE html PUBLIC W3C DTD XHTML 1 1 EN http www w3 org TR xhtml11 DTD xhtml11 dtd gt XHTML Basic DTDs Edit XHTML Basic 1 0 lt DOCTYPE html PUBLIC W3C DTD XHTML Basic 1 0 EN http www w3 org TR xhtml basic xhtml basic10 dtd gt XHTML Basic 1 1 lt DOCTYPE html PUBLIC W3C DTD XHTML Basic 1 1 EN http www w3 org TR xhtml basic xhtml basic11 dtd gt HTML5 DTD less DOCTYPE Edit 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 7 In the words of the specification draft itself In other words span class cp lt DOCTYPE html gt span 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 span class cp lt DOCTYPE html gt span 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 8 However if the markup is to be processed as both XML and HTML a DOCTYPE should be used 9 See also EditDocument type definition contains an example RDFa XML schemaReferences Edit HTML2 HTML3 HTML4 The HTML syntax HTML5 Retrieved 2011 06 05 DOCTYPE Declaration msdn microsoft com The DOCTYPE Declaration Archived from the original on 2011 08 14 Retrieved 2011 09 09 W3C QA Recommended list of Doctype declarations you can use in your Web document www w3 org Retrieved 22 March 2019 HTML Standard html spec whatwg org Retrieved 22 March 2019 The HTML syntax HTML5 Web Hypertext Application Technology Working Group Retrieved 2011 06 05 3 A string that is an ASCII case insensitive match for the string DOCTYPE 5 A string that is an ASCII case insensitive match for the string HTML The XHTML syntax HTML5 Web Hypertext Application Technology Working Group Archived from the original on 2012 06 18 Retrieved 2009 09 01 Polyglot Markup HTML Compatible XHTML Documents World Wide Web Consortium Retrieved 2012 01 17 External links Edit Look up doctype in Wiktionary the free dictionary Wikibooks has a book on the topic of Authoring Webpages HTML XHTML and DOCTYPEs 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 Retrieved from https en wikipedia org w index php title Document type declaration amp oldid 1107377622, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.