CSS Cascade: Author Styles vs User-Agent Defaults
In the CSS cascade, author stylesheets and user-agent defaults
represent two distinct origins of style rules that determine how a
browser renders a web page. Normal declarations written in author
stylesheets inherently outweigh standard user-agent defaults, allowing
web developers to easily override native browser styling. However, when
the !important flag is applied, the hierarchy completely
inverts, granting user-agent declarations absolute precedence over
author rules.
The Role of Cascade Origins
The CSS cascade resolves conflicts between multiple styles targeting the same element. Before evaluating specificity or source order, the browser sorts declarations by their origin and importance.
The CSS specification defines three primary origins:
- User-Agent: The default styles provided by the web
browser (e.g., default margins, display properties like
blockfor<div>, and link colors). - User: Custom styles configured by the user visiting the site (such as custom accessibility settings).
- Author: The custom stylesheets, embedded
<style>tags, and inline styles created by the web developer.
Normal Declarations: Author Precedence
For standard, non-!important CSS rules, author
stylesheets have a higher cascade weight than user-agent defaults.
The order of precedence for normal declarations from lowest to highest is:
- User-agent declarations (Lowest)
- User declarations
- Author declarations (Highest)
Because origin precedence is evaluated before specificity, any
standard author rule will automatically override a user-agent rule,
regardless of the selectors used. For instance, a basic author rule like
h1 { margin: 0; } will successfully override the browser's
default margin-block or margin on headings,
even though the author selector has a minimal specificity of
(0, 0, 1).
Important Declarations: The Inversion
The relationship between author stylesheets and user-agent styles
changes when !important is used. The CSS specification
intentionally inverts the origin hierarchy for !important
declarations to ensure that critical browser and user requirements
cannot be broken by website authors.
The order of precedence for !important declarations from
lowest to highest is:
- Author
!importantdeclarations (Lowest) - User
!importantdeclarations - User-agent
!importantdeclarations (Highest)
If a browser marks an internal rule with !important
(often used internally for secure UI elements, form control behaviors,
or strict accessibility requirements), no author declaration—even one
marked !important—can override it.
Key Takeaway
Under standard conditions, author styles effortlessly override
user-agent defaults without requiring high-specificity selectors. The
cascade weight heavily favors the author for normal styling, but
reserves ultimate control for the user-agent when
!important protections are enforced.