You are here: Reference > JavaScript > client-side > HTML DOM > objects > doctype

doctype object

Browser support:
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
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, "".
Commonly used document types: Excluding special cases, the use of the HTML5 document type is recommended.
Document type Declaration
XHTML 1.1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
XHTML 1.1 Strict <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "">
XHTML 1.1 Transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "">
XHTML 1.1 Frameset <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Frameset//EN" "">
XHTML 1.0 Strict <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
XHTML 1.0 Transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
XHTML 1.0 Frameset <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">
HTML 4.01 Strict <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
HTML 4.01 Transitional <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
HTML 4.01 Frameset <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "">


Properties that reference the object:
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:

Returns the base URL for the object.
Returns a collection of available entity nodes in the document.
Returns the entire contents of the doctype element as a string.
Returns the name of the doctype element.
Returns a reference to the next child of the current element's parent.
Returns the name of the current node.
Returns an integer that indicates the type of the node.
Returns the type of the current node as a string.
Sets or returns the value of the current node.
Returns a collection of notation nodes within the current doctype element.
Returns the document object that contains the current node.
Returns the parent element of the current node in the DOM hierarchy.
Returns a reference to the previous node of the current element's parent.
Returns the public identifier portion of the doctype element.
Returns the system identifier portion of the doctype element.

Example HTML code 1:

This example shows how to set the character encoding of the document in HTML5:
<!DOCTYPE html>
    <meta charset="utf-8" />
Did you find this example helpful? yes no

Example HTML code 2:

This example shows how to set the character encoding of the document in document types other than HTML5:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Did you find this example helpful? yes no

Example HTML code 3:

This example illustrates the use of the doctype object:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
        <script type="text/javascript">
            function GetDocType () {
                if (document.doctype) {
                    var docTypeName =;
                    var pubIdStr = document.doctype.publicId;
                    var sysIdStr = document.doctype.systemId;

                    var message = "Document type: " + docTypeName;
                    message += "\nDOCTYPE publicId: " + pubIdStr;
                    message += "\nDOCTYPE systemId: " + sysIdStr;
                    alert (message);
                else {
                    alert ("Your browser does not support this example!");
        <button onclick="GetDocType ();">Get DOCTYPE properties!</button>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content