CSS cascade is the algorithm that chooses a single winning declaration for each property on each element when several rules compete. It is defined in the W3C CSS Cascading and Inheritance module, and Level 5 added cascade layers. The part people search for is the sort order: origin and importance, context, element-attached styles, layers, specificity, then order of appearance.
The cascade compares two declarations one criterion at a time and stops at the first criterion that differs. Level 5 lists them in descending priority:
style attribute beats rules of the same importance.The cascade produces the cascaded value. Defaulting then gives the specified value, and resolving relative values gives the computed value. Inheritance happens in the defaulting step, only when the cascade produced no value.
@layer base, theme;
@layer base { #x.y.y { color: red; } }
@layer theme { p { color: green; } }
Computed color of <p id="x" class="y"> in headless Chromium 141:
rgb(0, 128, 0)
The red rule has specificity (1,2,0) against (0,0,1), but theme was declared after base, so layer order decides before specificity is read.
No, it only wins inside its own bucket. An important author declaration beats a normal one, but an important user-agent or user declaration beats it. Inside layers the order flips. With base declared before theme and color marked important in both, plus an important unlayered rule, the winner in Chromium 141 was the base rule, rgb(255, 0, 0). The first layer wins for important rules, and important layered rules beat important unlayered ones.
It rolls the value back to the previous origin. In an author rule, revert discards author declarations for that property and uses the user or user-agent value. revert-layer rolls back only to the layer below.
@layer loses to your plain stylesheet whatever its selectors say. That is by design, and it is the main reason to layer third-party CSS.!important will find the resets override everything later.a links stay blue because the user-agent sheet sets a:link, and an inherited color on a parent never reaches them.getComputedStyle returns computed or used values, not the declaration that won.