Check doctype.document.doctype is null when no doctype node exists.
Read mode. Log compatMode next to that boolean for a clear debug pair.
Healthy case. HTML5 pages usually have both a doctype and CSS1Compat.
Fix tip. Missing doctype? Add <!DOCTYPE html> as the first line of the file.
Compatibility
Browser Support
Document.compatMode is Baseline Widely available on MDN (since July 2015). It works across modern browsers for detecting quirks vs standards-like rendering.
✓ Baseline · Widely available
Document.compatMode
Read-only string: BackCompat (quirks) or CSS1Compat (standards / almost-standards).
99%Browser support
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
compatModeExcellent
Bottom line: Safe everywhere you teach DOM APIs. Always ship <!DOCTYPE html> so production pages stay in standards mode (CSS1Compat).
Frequently Asked Questions
A read-only string: "BackCompat" when the document is in quirks mode, or "CSS1Compat" when it is in no-quirks (standards) mode or limited-quirks (almost standards) mode.
No. MDN marks Document.compatMode as Baseline Widely available (since July 2015). It is a standard way to detect rendering mode.
Usually a missing or incomplete HTML doctype. Modern pages should start with <!DOCTYPE html> so the browser uses standards (CSS1Compat) mode.
MDN: the document is in no-quirks mode (standards) or limited-quirks mode (almost standards). Both report CSS1Compat via compatMode.
They are historical. MDN notes that these modes are now standardized, so older "standards" / "almost standards" marketing names are less meaningful today.
No. It is read-only. Fix the doctype (and related markup) so the browser chooses the mode you want — typically standards mode with <!DOCTYPE html>.