doctype object
Represents a Document Type Definition (DTD).
The DTD can be specified with the !DOCTYPE element in HTML and XML documents.
With the doctype object, type declarations like entities, notations and the name of the DTD can be retrieved, furthermore the DTD can be specified for a XML documents (see the createDocumentType method).
Note: In Internet Explorer, the doctype object is not supported in HTML documents only in XML documents.
The document.doctype property always returns null in that browser.
The following section describes the document type definition in HTML and XML.
!DOCTYPE element:
Each HTML and XML document can have only one !DOCTYPE element and it must be placed before the root element (the html element in HTML documents) of the document.
The DTD specifies the syntax of the document and affects the visual appearance of the page.
<!DOCTYPE RootElement Availability "URI" [declarations]>
| parts of DOCTYPE | Available values | ||||||
|---|---|---|---|---|---|---|---|
| RootElement |
Specifies the top-level element of the document
|
||||||
| Availability |
Specifies whether the FPI (formal public identifier) is a system resource or open to the public.
|
||||||
| 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". |
Commonly used document types:
Excluding special cases, the use of the XHTML 1.1 DTD doctype is recommended.
| Document type | Declaration |
|---|---|
| XHTML 1.1 DTD: | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| XHTML 1.1 Strict DTD | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| XHTML 1.1 Transitional DTD | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| XHTML 1.1 Frameset DTD | <!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"> |
Syntax:
Properties that reference the object:
| | object.doctype |
Related objects:
|
Methods that return the object:
| | implementation.createDocumentType (qualifiedName, publicID, systemID) |
The base interface, through which you can add new functionalities to the doctype object, is the DocumentType interface.
If you want to see the HTML objects by categories, please visit this page.
| HTML page for this element: !DOCTYPE |
Possible members:
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example HTML code 1:
This example illustrates the use of the !DOCTYPE element:
|
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> </html> |
|||
|
|||
|
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the doctype object:
|
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <script type="text/javascript"> function GetDTD () { var dtd = document.doctype; // Internet Explorer always returns null. if (dtd) { alert ("the dtd name: " + dtd.name + "\n The publicId: " + dtd.publicId + "\n The systemId: " + dtd.systemId); } } </script> </head> <body> <button onclick="GetDTD ();">Show DocType!</button> </body> </html> |
||||
|
||||
|
Did you find this example helpful?
|
Related pages:
External links:
Recommended list of DTDs (W3C)
doctype (MSDN)
doctype (Mozilla Developer Center)
doctype (W3C DOM Level 2)
doctype (W3C DOM Level 3)
doctype (MSDN)
doctype (Mozilla Developer Center)
doctype (W3C DOM Level 2)
doctype (W3C DOM Level 3)
User Contributed Comments

