CSS cascade
The CSS process that decides which of several competing rules sets a property on an element.
In more detail
The browser compares where each rule comes from, its specificity and its order in the stylesheets; the order of class names in the HTML class attribute plays no part. Separately, some properties, including custom properties, are inherited from parent to child elements. Together these let a theme set on one element flow down to everything inside it.
Example
In the browser: It compares, in order: origin and importance, then cascade layer, then specificity, then source order. The first step that finds a difference decides the winner, so specificity only matters when origin and layer are equal.Related terms
- specificity — The weight the browser gives a CSS selector, used to decide which rule wins when two set the same property.
- CSS custom property — A value you name yourself in CSS, such as --color-primary: #2563eb, and use elsewhere with var(--color-primary).
- CSS — The language that describes how web pages look: colours, fonts, spacing, layout and animation.
- cascade origin — Where a CSS declaration comes from: the browser's own defaults, the user's settings, or the page author, which the cascade ranks first.
- cascade layer — A named group of CSS rules, declared with @layer, whose priority in the cascade is set by layer order instead of selector specificity.
- source order — The order in which CSS rules appear; when everything else ties, the rule that comes later wins.
- !important — A flag added to a CSS declaration that moves it into a higher-priority group of the cascade, above all normal declarations.
Taught in
- CSS Custom Properties & Dynamic Theming Architecture — Design Systems & Component Engineering
- Class Variance Authority: Type-Safe Variant & Prop Orchestration — Design Systems & Component Engineering
- CSS Parsing, The CSSOM And The Render Tree — Frontend Architecture & Web Platform
- The Cascade Algorithm: Specificity, Inheritance And Source Order — Frontend Architecture & Web Platform
- CSS Cascade Layers: Taming Specificity Wars with @layer — Frontend Architecture & Web Platform