skip to content

A user-origin stylesheet declares body { font-size: 20px !important } and the site's author stylesheet declares body { font-size: 12px !important }. Which declaration wins, and what cascade rule decides it?

level: seniorimportance: should knowfreq 38%

answer

  1. two ladders, one is upside down
  2. !important is a bucket, not a score
  3. normal: user-agent, user, author
  4. important half reverses that order
  5. it is an accessibility guarantee

basics

~20 s

The user's 20px wins. Marking a declaration !important moves it into the important band, where the normal origin order is inverted: important user-agent beats important user, which beats important author. A site cannot override a user's important declaration.

solid answer

~40 s

The user's `20px` applies. `!important` is not a "win" switch — it moves the declaration into a second set of origin buckets whose order is the reverse of the normal one. For normal declarations the order weakest to strongest is user-agent, user, author, so your styles beat both. For important declarations it flips: author is weakest, then user, then user-agent. That inversion is deliberate and it is an accessibility guarantee: a user who forces a minimum font size, a high-contrast colour or a larger line height must be able to do so on a site that also uses `!important`. The practical consequence is that there is no author-side declaration you can write that beats a user's important one — not a longer selector, not an inline style, not another `!important`.

code

css · 5 lines
css
/* user stylesheet (user origin) */
body { font-size: 20px !important; }

/* site stylesheet (author origin) */
body { font-size: 12px !important; }

go deeper

for a junior

Know that !important is a flag on a single declaration, written before the semicolon, and that it outranks any normal declaration regardless of selector strength. Do not describe it as a specificity number.

for a middle

Explain the six origin-and-importance buckets and state that the important half is the normal half reversed. Be able to work out which of two competing declarations wins from their origins alone.

for a senior

Show the judgment: recognise a user override as a guarantee you must not fight, diagnose which bucket a rogue declaration sits in before reacting, and explain why author !important wars escalate once importance stops being a tiebreak.

for a principal

Own the policy question — where !important is legitimate in a shared codebase versus a symptom, and how respecting user-origin overrides shapes an accessibility commitment your teams can actually keep.

## Two ladders, not one The first sort criterion of the cascade is "origin and importance", and the usual mental model — three origins in a line — is only half of it. There are three origins (**user-agent**, **user**, **author**) and each contributes two buckets, a normal one and an important one. Ordered weakest to strongest, the buckets are: ``` 1. user-agent normal 2. user normal 3. author normal 4. author !important 5. user !important 6. user-agent !important ``` The top half is the bottom half reversed. That is the whole answer to the question: both declarations are important, one is user-origin and one is author-origin, and in the important half user outranks author. `20px` wins, and no further step of the cascade is consulted. ## What `!important` actually is `!important` is a per-declaration flag written before the semicolon: `font-size: 20px !important;`. It applies to that one declaration, not to the rule; a rule can mix important and normal declarations freely. On a shorthand it marks every longhand the shorthand expands to. It is not a specificity value — it never appears in the specificity triple, and adding it cannot be "out-specificitied" by a longer selector, because importance is compared strictly before specificity. ## Why the inversion exists If `!important` simply meant "strongest", the author would always be able to have the last word, since authors write far more CSS than users do. The user origin exists so that a person can impose their own reading requirements: a minimum font size, a forced foreground/background pair, wider spacing, reduced decoration. Those overrides are worthless if the site can beat them. Inverting the important half gives the user a lever the page cannot take away — and gives the browser itself, at the top, a lever the user cannot accidentally destroy (user-agent important declarations are rare and are reserved for things the browser must guarantee). The same inversion principle appears elsewhere in the cascade — importance flips the *layer* order too — but the origin inversion is the original and the one interviewers ask about. ## Where user-origin styles actually come from In practice user-origin declarations reach the page through browser settings and user stylesheets. Firefox reads a `userContent.css` file from the profile's `chrome` directory as user-origin CSS, and browser accessibility settings (minimum font size, forced colours) act at this level too. Note that not everything a user *installs* is user-origin: styles injected by an extension's content script are typically author-origin unless the extension explicitly asks for the user origin, so an extension's `!important` may well lose to yours. ## What this means for you as an author First, stop treating `!important` as a hierarchy-free trump card in your own head; it is one bucket among six, and the only bucket you can write into is the weakest of the important half. Second, if a user override is beating your styles, that is the system working — do not hunt for a way around it, because there is none, and attempting one usually degrades the page for exactly the people the override protects. Third, and most useful day to day: because importance is compared before specificity, an author `!important` collides only with other author `!important` declarations. Inside that bucket the cascade keeps going — element-attached styles, then layers (in inverted order), then specificity, then source order. So a second `!important` in a more specific author rule *does* beat the first, which is how `!important` wars start and why they end with every rule in a file carrying the flag. ```css /* both important, both author: the cascade continues down the list */ .card p { color: #333 !important; } /* 0,2,0 */ p { color: #999 !important; } /* 0,0,1 — loses on specificity */ ``` ## Answering it well in an interview Say which one wins, then say *why* in terms of buckets rather than strength: `!important` relocates a declaration into the inverted half of the origin ordering. Naming the accessibility rationale unprompted is the part that separates a memorised answer from an understood one. And be ready for the obvious follow-up — what happens with a *normal* user declaration against a normal author one — where the ordinary, non-inverted order applies and the author wins.

  • What if the user's declaration had been normal rather than important — would your author !important still lose?
    No. With the user declaration normal, the ordinary origin order applies: user-agent normal, then user normal, then author normal, then the important buckets above all of them. Your author `!important` sits above every normal declaration from any origin, so `12px` would win. The inversion only exists between important declarations.
  • Two author declarations are both !important. What decides between them?
    The cascade simply continues down its list inside that bucket: element-attached (`style` attribute) declarations first, then cascade layer order — which importance also inverts, so an earlier-declared layer wins among important declarations — then specificity, then source order. `!important` never ends the comparison; it only settles the first step.
  • Why is a browser extension's !important sometimes beaten by the site's own !important?
    Because extension styles are not automatically user-origin. A content script that injects a stylesheet normally lands in the author origin, putting it in the same bucket as the site's own important declarations, where layer order, specificity and source order decide. Only styles genuinely inserted with the user origin get the inverted-precedence advantage.

saying these in an interview costs you the question

  • Says !important always wins no matter where it comes from
  • Puts author above user in the important ordering
  • Treats !important as an extremely high specificity value
  • Thinks a more specific author selector can beat a user !important
  • Believes every browser extension's styles are user-origin

context