Quirks mode is a document rendering mode in which a web browser deliberately reproduces legacy, nonstandard layout and CSS behavior so that pages written for late-1990s browsers still display as their authors intended. Among browser technologies on the Web, it is one of three modes the rendering engine chooses before it lays out a single element, and the choice depends almost entirely on the DOCTYPE declaration at the top of the HTML document.
The other two modes are no-quirks mode, often called standards mode, and limited-quirks mode, historically called almost standards mode. Modern pages should always run in no-quirks mode, because quirks mode changes sizing, selector matching and scrolling in ways that are hard to debug.
How the browser selects quirks mode
The HTML parser decides the mode once, while it reads the DOCTYPE token, and the decision cannot be changed later by scripts or style sheets. The rules are specified in the WHATWG HTML Living Standard, so Blink, WebKit and Gecko now trigger the modes almost identically.
The short declaration <!DOCTYPE html> always produces no-quirks mode. A missing DOCTYPE, a malformed one or a list of legacy public identifiers from HTML 2.0, HTML 3.2 and early HTML 4 drafts produce quirks mode. The table below shows typical cases.
| Document start | Resulting mode | Note |
|---|---|---|
<!DOCTYPE html> | No-quirks | Recommended for all new pages |
| No DOCTYPE at all | Quirks | Most common accidental trigger |
| HTML 4.01 Transitional without system identifier | Quirks | Legacy identifier list |
| HTML 4.01 Transitional with system identifier | Limited-quirks | Only table cell line height differs |
| XHTML 1.0 Transitional | Limited-quirks | Same narrow difference |
| Comment or text before DOCTYPE | Quirks in old IE | Modern parsers tolerate comments |
Some documents never enter quirks mode: XML documents served as XHTML, and iframes created with the srcdoc attribute, which are always rendered in no-quirks mode. Each iframe has its own mode, so a standards-mode page can embed a quirks-mode frame.
Behaviors that change in quirks mode
Quirks mode is not a single switch but a catalog of specific deviations, collected in the WHATWG Quirks Mode specification and in the CSS specifications. Each quirk exists because widely used old pages depended on it, and removing it would break them.
The following table lists the deviations that most often surprise developers.
| Quirk | Behavior in quirks mode | Behavior in no-quirks mode |
|---|---|---|
| Percentage heights | Resolve against the viewport through auto-height ancestors | Compute to auto when the parent height is auto |
| Body height | Body fills the viewport | Body is as tall as its content |
| Class and ID selectors | Matched case-insensitively | Matched case-sensitively |
| Unitless lengths | width: 200 is read as pixels | Declaration is ignored as invalid |
| Hashless colors | color: ff0000 is accepted | Declaration is ignored as invalid |
| Table font inheritance | Tables do not inherit font size | Tables inherit normally |
| Scrolling element | document.body scrolls the page | document.documentElement scrolls the page |
Historically, Internet Explorer in quirks mode also used its old box model, in which declared width included padding and border. Modern engines do not apply that model to all elements; the equivalent behavior is now available deliberately through box-sizing: border-box.
Quirks mode compared with the other rendering modes
The three modes differ in how much legacy behavior they keep. Limited-quirks mode was introduced to fix one painful problem: in strict mode, images inside table cells gained a gap below them because inline images sit on the text baseline, which broke sliced-image layouts.
| Mode | document.compatMode value | Scope of legacy behavior |
|---|---|---|
| No-quirks mode | CSS1Compat | None, follows current CSS specifications |
| Limited-quirks mode | CSS1Compat | Only the line height quirk in table cells |
| Quirks mode | BackCompat | Full set of documented quirks |
Because limited-quirks mode reports the same value as no-quirks mode, `document.compatMode` cannot distinguish them. Developer tools in Chromium and Firefox show a console warning when a page renders in quirks mode, which is the fastest way to detect the problem.
Quirks mode should also not be confused with browser compatibility views such as the old Internet Explorer document modes, which emulated entire earlier engine versions. Quirks mode is far narrower: the same modern engine runs the same JavaScript and supports the same CSS features, and only the listed legacy deviations are switched on. Performance and security are therefore unaffected; only layout and a few DOM properties change.
Why quirks mode still matters for developers
Quirks mode remains relevant because templates, email-generated pages, intranet systems and server-side includes frequently omit the DOCTYPE or emit output before it. The resulting bugs look like CSS errors, so teams often spend hours on layout fixes that address the symptom instead of the cause.
The table below connects typical symptoms with their cause and fix.
| Symptom | Likely cause | Fix |
|---|---|---|
| Height 100% works unexpectedly | Percentage height quirk | Add <!DOCTYPE html> and set explicit heights |
| Scroll position reads zero | Wrong scrolling element | Use document.scrollingElement |
| Selectors match mixed case | Case-insensitive matching | Fix the DOCTYPE and correct names |
| Fonts shrink inside tables | No font inheritance in tables | Fix the DOCTYPE first |
| Framework layout breaks | Library assumes standards mode | Remove output before the DOCTYPE |
- Place the DOCTYPE on the first line, before any whitespace emitted by templates where possible.
- Check `document.compatMode` in automated tests to catch regressions.
- Do not rely on quirks deliberately, because they are poorly documented outside the specifications.
- Remember iframes separately, since each embedded document has its own mode.
In everyday language
Web pages start with a short label that tells the browser which set of rules the page was written for. If that label is missing or very old, the browser assumes the page comes from the early days of the Web and switches on an old compatibility behavior called quirks mode.
It is a little like a modern car offering a setting that mimics an older model so that an old trailer still fits. Useful for very old pages, but new pages should never use it. One correct line at the top of the file avoids the problem.
Seen in the real world
A developer at a logistics company moved an internal dashboard to a new component framework. Every panel that used height: 100% collapsed, and a sticky header jumped on scroll, even though the same components worked in the framework’s demo pages. Two days went into adjusting CSS without success.
The developer then opened the browser console and saw a quirks mode warning. The legacy server template printed a hidden status comment and a tracking line before the HTML, and no DOCTYPE was emitted at all. After the template was changed to output <!DOCTYPE html> first, document.compatMode reported CSS1Compat, the panels rendered correctly and about 40 lines of workaround CSS were deleted.