Document.doctype is a read-only property that returns a DocumentType object for the document’s Document Type Declaration (DTD), or null if none exists (MDN).
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.doctype. Start with this line.
JavaScript
document.doctype
Call
What it does
document.doctype
Primary signature.
Built into the browser. Read or assign document.doctype — no import required.
Library declarations
JavaScript
document.doctype
Parameters
Parameter
Description
.publicId / .systemId
Optional. Legacy / XML DTD identifiers
Return Value
Return Value
Description
*
DocumentType or null
JavaScript Examples
Example 1 — Read doctype Safely
Null-check, then log the type name.
JavaScript
const dt = document.doctype;
if (dt) {
console.log(dt.name); // "html" on typical HTML5 pages
} else {
console.log("no doctype");
}
Print the type name. Confirms a doctype node is present.
Read compatMode. Shows standards vs quirks rendering.
Modern pages. Expect "html" + "CSS1Compat".
Fix in markup. Add <!DOCTYPE html> — you cannot set doctype via this property.
Compatibility
Browser Support
Document.doctype is Baseline Widely available (MDN: since July 2015). Returns a DocumentType or null.
✓ Baseline · Widely available
Document.doctype
Read-only DocumentType for the document’s DTD — supported across modern browsers.
99%Widely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
doctypeExcellent
Bottom line: Safe for production diagnostics. Always null-check, and keep <!DOCTYPE html> in your HTML files for standards mode.
Frequently Asked Questions
A DocumentType object representing the Document Type Declaration (DTD) associated with the current document, or null if there is no DTD.
No. MDN marks Document.doctype as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
For a normal HTML5 page with <!DOCTYPE html>, doctype.name is usually "html". publicId and systemId are typically empty strings.
No. MDN notes that DOM Level 2 does not support editing the document type declaration. The property is read-only.
When there is no DTD associated with the document — for example some programmatically created documents without a doctype node.
Missing or incorrect doctypes historically triggered quirks mode. Modern pages should include <!DOCTYPE html>. You can also check document.compatMode (CSS1Compat vs BackCompat).