doctype (W3C DOM Core property)

Version Depr. Static Read-only
DOM1 No No Yes
Browser support (more…)
IE5.5+ FF3+ SA1.3+ OP9+
Buggy Buggy Buggy Buggy


var dtd = document.doctype;

In the example above, the dtd variable is a reference to the Document Type Declaration for this document, which is an instance of the DocumentType interface, containing properties such as the name and publicId. So in this next example:

var pubid = dtd.publicId;

If we were on a page with an XHTML 1.0 Strict doctype, the pubid variable would have the value -//W3C//DTD XHTML 1.0 Strict//EN.


The Document Type Declaration of an XML document. For HTML documents, or XML documents without a document type declaration, this property should return null.

This property is readonly.


Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Buggy Buggy Partial Partial Buggy Buggy Buggy Buggy Buggy Buggy
Tip: Implementations are messy

And if you're lucky, you'll never need this!

In Internet Explorer 6 and 7 and Safari 1.3 and 2 in HTML mode1, the doctype property returns null. However this is according to specification — the doctype should only return an object in XML (including XHTML mode2), otherwise it should be null.

In Safari 1.3 and 2 in XHTML mode or XML the doctype property is available, but all its properties are null.

In Firefox 3 in HTML mode the name of a doctype is returned in uppercase.

Internet Explorer 5.5 in HTML does not implement this interface (doctype is undefined).

Internet Explorer in XML does not implement the internalSubset, publicId or systemId properties (they return undefined).

The relationship between the DocumentType node and its owning Document varies between browsers. While all which implement this interface have the correct ownerDocument, only Firefox has the document as its parentNode; in Opera and Safari 3 both properties are null. Firefox has the correct behavior.

Only Opera in XHTML mode or XML and Internet Explorer in XML return a populated entities collection; in Safari and Firefox it's null. In Internet Explorer in XML this collection only includes internal entities (those defined in a doctype's internal subset).

Only Opera in XHTML mode and Firefox in XHTML mode or XML provide data for the internalSubset property; in Safari it's null, in Internet Explorer it's undefined, and in other browsers and modes it's an empty string.


1 On XHTML or HTML pages served as text/html.

2 On XHTML pages served as application/xhtml+xml.

User-contributed notes

There are no comments yet.

Related Products