skip to content

What concrete layout differences does a browser's quirks mode produce compared with standards mode?

level: middleimportance: should knowfreq 44%

answer

  1. one rule set, not an old engine
  2. width swallows padding and border
  3. percentages resolve too eagerly
  4. invalid CSS values silently accepted
  5. gap under an inline image vanishes

basics

~20 s

Quirks mode restores legacy layout rules: a declared width includes padding and border, percentage heights resolve against ancestors standards mode treats as auto, unitless CSS lengths and hashless hex colours are accepted, and a line box holding only an image loses its descender gap.

solid answer

~40 s

The one that bites hardest is the box model: in quirks mode a declared `width` covers content **plus** padding and border, so a 300px box with 20px padding and a 10px border is 300px wide overall instead of 340px — the behaviour you would opt into today with `box-sizing: border-box`. Percentage heights also resolve more loosely, so `height: 100%` appears to work without every ancestor having a definite height. The CSS parser is looser too: quirks mode accepts lengths written without a unit and hex colours written without a `#`. And line boxes containing only an image are sized to the image, so the few pixels of descender space that normally appear under an inline `<img>` vanish. Everything else — flexbox, grid, custom properties, JavaScript — works exactly as usual.

go deeper

for a junior

At minimum, know that the box model flips: in quirks mode a declared width already contains padding and border. Being able to state that one difference with numbers is enough at this level.

for a middle

Name several differences and explain the mechanism behind each — content box versus border box, when a percentage height can resolve, and which invalid CSS values quirks mode tolerates. Say clearly what does not change.

for a senior

Reason about impact: which differences shift computed numbers silently, what breaks when a legacy page is switched to standards mode, and how you would detect the damage across many templates rather than one page.

for a principal

Own the policy question — why browsers keep the legacy rule set permanently, what that implies for any long-lived platform's compatibility guarantees, and how you keep quirks mode from creeping back into generated or third-party-embedded documents.

## The mental model Quirks mode is not "an older browser". It is today's engine running a small, fixed set of legacy layout and CSS-parsing rules so that pages authored before the specifications settled still look the way their authors intended. Everything else about the browser is unchanged: the same HTML parser, the same JavaScript engine, the same modern CSS features. Knowing *which* rules change is what separates a real answer from "quirks mode is bad, always add a doctype". ## 1. The box model This is the difference interviewers are fishing for. In standards mode, `width` and `height` size the **content box**; padding and border are added outside it. In quirks mode they size the **border box**, so padding and border eat into the declared size. ```css .box { width: 300px; padding: 20px; border: 10px solid; } /* standards mode: 300 + 40 + 20 = 360px wide on screen */ /* quirks mode: 300px wide, leaving 240px of content */ ``` The quirks behaviour is the same shape as `box-sizing: border-box`, which is why a stylesheet that already sets `border-box` everywhere is less exposed to the mode difference — though only for this one rule. ## 2. Percentage heights In standards mode a percentage `height` resolves only against a containing block with a definite height; if the parent's height is `auto`, the percentage does not resolve and the element behaves as `auto`. That is why the classic full-height layout needs height declared on the html and body elements before a child's `height: 100%` does anything. Quirks mode is more forgiving: it will resolve the percentage by looking further up, so `height: 100%` on a child often "just works". Stylesheets written against that assumption collapse the moment the document is switched to standards mode — one of the most common surprises during a migration. ## 3. Looser CSS parsing Quirks mode keeps two parsing hacks alive for authors who wrote CSS the way they wrote HTML attributes: ```css /* Both are invalid CSS, and both are honoured only in quirks mode */ .banner { width: 400; } /* unitless length quirk */ .banner { color: ff0000; } /* hashless hex colour quirk */ ``` In standards mode each of these declarations is simply dropped as invalid. Note that this cuts both ways: a stylesheet full of missing units may look fine in a quirks-mode page and lose half its declarations after the doctype is added. ## 4. The image gap in a line box An `<img>` is an inline-level element, so it sits on the text baseline, and the line box that contains it reserves room for the descenders of text that could sit alongside it. The result is the familiar few pixels of space under an image inside a container sized to it. ```html <div style="border: 1px solid"><img src="logo.png" alt="" width="100" height="40"></div> <!-- standards mode: a small gap below the image, inside the border --> ``` In quirks mode (and in almost-standards mode) a line box that contains no actual text is sized to its tallest inline box, so that gap disappears. Layouts of the table-and-sliced-image era depended on it being absent. ## 5. Table font inheritance Another documented quirk: font properties set on an ancestor do not inherit into tables the way they do in standards mode, so text inside a `<table>` can fall back to the browser's default face and size even though the surrounding page uses your typeface. ## What does *not* change Be explicit about this, because weak answers overreach: - No CSS or JavaScript feature is disabled. Grid, flexbox, custom properties, `async`/`await` all work. - Parsing and error recovery are identical — implied tags, auto-closing and unclosed-tag handling are the same algorithm. - Modern layout primitives are not "quirks-proof" as a class; a flex container still lays out normally, but the sizes you feed it are computed under the quirks box model. ## Why this matters beyond trivia The practical consequence is that quirks mode is not a cosmetic problem you can shrug off. Two of the five differences — the box model and percentage heights — change *numbers* rather than appearance, so bugs surface as a layout that is subtly wrong at some viewport widths rather than obviously broken. That is why the fix is always to switch the document to standards mode and correct the stylesheet, not to compensate for quirks behaviour inside CSS.

  • If a stylesheet already sets box-sizing: border-box on everything, is quirks mode harmless?
    No. It removes the most visible difference, because border-box matches the quirks box model, but the other rules remain: percentage heights still resolve differently, unitless lengths and hashless colours are still accepted, and line boxes containing only an image are still sized differently. A page can look almost right and still be wrong at specific viewport sizes.
  • Which quirks-mode differences are the most dangerous during a migration, and why?
    The box model and percentage heights, because they change computed numbers rather than visibly breaking. A page that switches to standards mode grows by the width of every padding and border, and full-height panes collapse to their content height. Both are easy to miss on a single test viewport and show up as subtle overflow or scrollbars in production.
  • Does quirks mode change how the browser parses HTML tags?
    No. Tokenising and tree construction — implied tags, auto-closed paragraphs and list items, unclosed-tag recovery — follow the same algorithm in every mode. The doctype switch affects layout and a couple of CSS parsing quirks only. If markup produces a different DOM, the cause is the markup, not the rendering mode.

saying these in an interview costs you the question

  • Says quirks mode disables flexbox, grid, or custom properties
  • Claims quirks mode changes how HTML tags are parsed
  • Thinks the box model is the only difference
  • Describes quirks mode as running an older rendering engine
  • Believes browsers dropped quirks mode years ago

context