When Multiple Rules Match, the Cascade Decides
The Cascade
The cascade is the algorithm CSS uses to pick a winner among conflicting rules — by origin, importance, specificity, and source order.
What you'll learn
- Read the cascade order
- Know what `!important` does (and when to use it)
- Recognize layer effects (coming next lesson too)
When several rules match the same element and set the same property, the cascade picks the winner. Four factors, in priority order.
The Order (Highest Priority Last)
- Origin and importance — user-agent vs author vs user, plus
!importantflag - Cascade layer — later layers beat earlier (coming up in Modern CSS)
- Specificity — more specific selectors win (next lesson)
- Source order — later rules beat earlier ones if everything else ties
Origin (Usually Doesn’t Matter)
| Origin | Where it comes from |
|---|---|
| User-agent | Browser’s built-in defaults |
| User | User-configured browser CSS (rare) |
| Author | YOUR stylesheets |
Author CSS overrides browser defaults. You almost never need to
think about origin — until !important enters the picture.
!important
A declaration with !important jumps ahead of all non-important
rules at the same origin:
.warn {
color: red !important;
} Now any other rule trying to override color on .warn loses,
unless it’s ALSO !important with higher specificity.
Legitimate uses:
- Utility class overrides (e.g., Tailwind’s
!prefix) - Overriding a third-party library you can’t edit
- Print styles that must win
Source Order — The Tiebreaker
When two rules have the same specificity and no !important, the
later one wins.
.btn { background: blue; }
.btn { background: green; } /* wins — same specificity, later */ This is why bundling order matters — Tailwind utilities load last so they can override your component styles.
Sources of Rules in Order
For a single page, browsers compute styles by considering:
- Browser defaults (low)
- Linked stylesheets (in
<link>order) <style>blocks (in document order)- Inline
styleattributes (high) !importantoverrides (highest)
Inheritance Is Different
The cascade picks among directly matching rules. If no rule matches, some properties (color, font) are inherited from the parent — that’s the next-but-one lesson.
Up Next
The most-misunderstood half of the cascade: specificity.
Specificity →