Document.doctype is a read-only instance property that returns a DocumentType object for the document’s Document Type Declaration (DTD), or null if none exists. Learn name, publicId, systemId, how HTML5 doctypes look, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
DocumentType
03
Or
null
04
HTML5
name "html"
05
Edit?
Not via DOM
06
Status
Baseline widely
Fundamentals
Introduction
At the top of almost every HTML file you write <!DOCTYPE html>. That line is the document type declaration. It tells the browser which kind of document rules to use (and historically avoided quirks mode).
MDN: document.doctype is the read-only DocumentType object for that declaration. If the document has no DTD, the property is null. You cannot edit the doctype through the DOM (DOM Level 2 does not support editing it).
💡
HTML5 in practice
For <!DOCTYPE html>, expect doctype.name === "html" with empty publicId and systemId. Older XHTML/HTML4 doctypes carried longer public/system identifiers.
Main has doctype: true
Fresh doctype: [object DocumentType]
Fresh name: html
How It Works
MDN: the property returns null when no DTD is associated. Always optional-chain in shared helpers. (createHTMLDocument often includes an HTML doctype in modern browsers.)
Example 5 — Pair with compatMode
Doctype presence and rendering mode are related diagnostics.
Document.doctype is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.doctype
Read-only DocumentType for the document's DTD — or null if none is associated.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported (legacy)
Full support
Document.doctypeExcellent
Bottom line: Use document.doctype to inspect the DocumentType. Always include in HTML source — you cannot set the doctype from JavaScript.
Wrap Up
Conclusion
Document.doctype exposes the parsed Document Type Declaration as a DocumentType node. On modern HTML5 pages that usually means name: "html". Read it for diagnostics; fix doctypes in your HTML source, not with a JavaScript assignment.
Ship pages without a doctype (risk of quirks mode)
Confuse doctype with contentType (MIME)
Rely on legacy public/system ids for modern HTML5 apps
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.doctype
Read-only DocumentType — or null when missing.
5
Core concepts
📄01
Returns
DocumentType
API
✓02
Status
baseline
Standard
🔒03
Access
read-only
DOM
⚠️04
Missing
null
MDN
🎯05
HTML5
name html
Typical
❓ 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 a standard read-only Document instance property.
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).
Did you know?
Before HTML5’s short <!DOCTYPE html>, authors copied long SGML-style doctypes with public and system identifiers. Those still appear as non-empty publicId / systemId on document.doctype when you open old pages.