Document.compatMode is a read-only instance property that tells you whether the page is rendered in quirks mode or standards (no-quirks / limited-quirks) mode. Learn the BackCompat and CSS1Compat values, how the doctype chooses the mode, and how to check it in JavaScript—with five examples and try-it labs.
01
Kind
Read-only
02
Returns
string
03
Quirks
BackCompat
04
Standards
CSS1Compat
05
Fix via
<!DOCTYPE html>
06
Status
Baseline widely
Fundamentals
Introduction
When a browser loads HTML, it chooses a rendering mode. Pages with a proper doctype (such as <!DOCTYPE html>) usually run in standards mode. Pages without a doctype may fall into quirks mode, where layout rules behave more like old browsers.
document.compatMode exposes that choice as a simple string. It is useful when debugging weird box-model or percentage-height bugs on legacy pages—or when confirming a template always ships a doctype.
💡
Always start HTML with a doctype
Put <!DOCTYPE html> as the first line of every modern HTML document. That is the simplest way to get CSS1Compat (standards) rendering.
Document.compatMode 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.compatMode
Read-only quirks vs standards mode string — essential for doctype and layout debugging.
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 in legacy IE
Full support
Document.compatModeExcellent
Bottom line: Use document.compatMode to detect quirks mode. Prefer CSS1Compat by always including . Do not try to set the mode from JavaScript.
Wrap Up
Conclusion
Document.compatMode is the standard way to ask whether a page is in quirks mode (BackCompat) or standards-like mode (CSS1Compat). Use it for diagnostics—and keep modern pages in standards mode with a proper HTML5 doctype.
Log compatMode when debugging mysterious layout bugs
Prefer CSS1Compat for all new projects
Audit CMS/theme output for a missing doctype
Pair mode checks with document.doctype during support
❌ Don’t
Ship HTML without a doctype
Try to assign document.compatMode = "CSS1Compat"
Build feature detection around quirks mode in new apps
Assume every CSS1Compat page is perfectly modern CSS
Ignore quirks mode warnings on legacy intranet pages
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.compatMode
Read-only mode string — prefer CSS1Compat with an HTML5 doctype.
5
Core concepts
📄01
Returns
string
API
✓02
Status
baseline
Standard
⚠️03
Quirks
BackCompat
Legacy
🎯04
Standards
CSS1Compat
Preferred
📝05
Fix via
DOCTYPE
HTML
❓ 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 quirks, standards, and almost-standards modes are now standardized, so older 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>.
Did you know?
Quirks mode was invented so old pages without doctypes would keep looking roughly like they did in 1990s browsers. Modern sites almost never want that—which is why a one-line <!DOCTYPE html> is still one of the most important habits in web development.