The seven questions the CSS cascade asks, in order, where !important flips the answer, and how scope proximity fits after specificity despite what one sentence of the spec says.
Contents · 11 sections
The stock answer to "why doesn't my style apply?" is specificity. Sometimes that's right. Often it isn't, because specificity is the fifth question the cascade asks, not the first. By the time two declarations get compared on IDs and classes, the browser has already checked where they came from, whether they're !important, which shadow tree they live in, whether one is a style attribute, and which cascade layer each belongs to. Since @scope arrived, there's a sixth question after specificity, too.
The folk model most of us carry around ("origin, then specificity, then source order, and !important beats everything") was a decent approximation before shadow DOM, cascade layers and @scope. Today it's wrong in ways that matter. An !important declaration in your first layer beats an !important declaration outside any layer. A :host rule loses to a plain type selector in the page until both are !important, and then it wins. A scoped rule beats an unscoped one only when their specificity ties, even though one sentence in the current Editor's Draft says the opposite.
This piece walks the whole comparator in order, using the CSS Working Group's own text, then works through ten conflicts. I ran all ten through getComputedStyle in four engines and checked the matching Web Platform Tests against the latest stable runs. All status facts were checked on 18 October 2026. The CSS current work page lists Cascading and Inheritance Level 5 as a Candidate Recommendation; its TR copy is the Candidate Recommendation Snapshot of 13 January 2022, and the Editor's Draft is dated 13 April 2026. Level 6, which adds @scope, is a Working Draft: the TR copy is dated 6 September 2024, and the Editor's Draft 28 April 2026. If you haven't read Why CSS has no version, that's the background for why a "Level 6" can be a Working Draft and still ship everywhere.
The cascade is a comparator with seven keys
Before anything is sorted, the browser filters. Cascade 5 §5 says a declaration applies to an element only if its style sheet currently applies to the document, it isn't inside a conditional rule whose condition is false, its rule's selector matches the element (taking scoping into account), and it's syntactically valid. A declaration with an unknown property or a value the browser can't parse never reaches the cascade. That's why a typo can look like a cascade problem: there's nothing to win, because the declaration was thrown away before the contest started.
What survives filtering is, per property per element, an unordered list of declared values. The cascade "sorts them by their declaration's precedence" and "outputs a single cascaded value." The sort is defined in Cascade 6 §3.1, which lists the criteria "in descending order of precedence":
- Origin and Importance
- Context
- The Style Attribute
- Layers
- Specificity
- Scope Proximity
- Order of Appearance
"Descending order of precedence" means this is a lexicographic comparison, like sorting rows by a tuple. Compare two declarations on the first key. If one wins, you're done, and nothing further down the list is ever consulted. Only on a tie do you move to the next key. If you keep one thing from this piece, keep this: a criterion can only break ties left by every criterion above it. Specificity can never rescue a declaration that lost on layers, and proximity can never rescue one that lost on specificity.
Fig. 1 shows the comparator as a stack of rows. Two declarations drop through it; at each row they either tie and fall through, or one wins and the rows below go dark.
Level 5 and Level 6 give the same list with two differences. Cascade 5's version has no scope proximity step, because @scope lives in Level 6. And Level 5 calls step 3 "Element-Attached Styles" where Level 6 calls it "The Style Attribute"; the anchor is #style-attr in both, and the rule is worded identically (Level 5 adds a pointer to the Style Attributes spec and a note on presentational hints).
There's a third difference I only found by diffing the documents. The 2024 Working Draft of Level 6 says of specificity: "Each declaration has the same specificity as the style rule it appears in. The declaration with the highest specificity wins." The current Editor's Draft says: "When comparing declarations from two style rules, the declaration belonging to the style rule with the highest specificity wins." The new phrasing makes explicit that specificity is a property of style rules, which matters for the style attribute (more on that below). Nothing else in §3.1 differs between the two drafts, apart from section numbers: the Editor's Draft added a section on @import before the cascade, so the Working Draft's §2.1 is the Editor's Draft's §3.1.
If it helps to see the comparator as code, here's a model of it. It's a reasoning aid, not how any engine implements the cascade, and it ignores the presentational-hint origin covered in the next section.
// A model of the Cascade 6 sort, for reasoning, not an engine.
// Highest precedence first.
const ORIGINS = [
'transition', 'ua!', 'user!', 'author!',
'animation', 'author', 'user', 'ua',
];
const cmp = (x, y) => (x < y ? -1 : x > y ? 1 : 0);
function compareSpecificity([a1, b1, c1], [a2, b2, c2]) {
return cmp(a1, a2) || cmp(b1, b2) || cmp(c1, c2);
}
// Negative: a wins. Positive: b wins.
export function cascadeCompare(a, b) {
const key = (d) => d.origin + (d.important ? '!' : '');
const important = a.important; // equal once origins tie
return (
// 1. Origin and importance
cmp(ORIGINS.indexOf(key(a)), ORIGINS.indexOf(key(b))) ||
// 2. Context: index in shadow-including tree order, 0 = document.
// Normal: outer (lower) wins. Important: inner (higher) wins.
(important ? cmp(b.context, a.context) : cmp(a.context, b.context)) ||
// 3. The style attribute beats style rules
cmp(Number(b.styleAttr), Number(a.styleAttr)) ||
// 4. Layers: index in layer order, unlayered = Infinity.
(important ? cmp(a.layer, b.layer) : cmp(b.layer, a.layer)) ||
// 5. Specificity: higher wins
compareSpecificity(b.specificity, a.specificity) ||
// 6. Scope proximity: fewer hops wins, unscoped = Infinity
cmp(a.hops, b.hops) ||
// 7. Order of appearance: later wins
cmp(b.order, a.order)
);
}I checked the model in Node against the ten conflicts later in this piece, plus the two animation cases in the next section; it picks the same winner as the engines did in every one. Notice the three places where important flips a comparison. Those are the three inversions, and they're exactly what the folk model leaves out.
Origin and importance: eight levels, and !important flips the middle
The first key combines two things: where a declaration came from, and whether it carries !important. Cascade 5 §6.2 defines three core origins (author, user and user agent) and two that CSS extensions add: animations, which "generate 'virtual' rules representing their effects when running", and transitions, which do the same. Cascade 6 §3.1 then orders the combinations, highest first:
- Transition declarations
- Important user agent declarations
- Important user declarations
- Important author declarations
- Animation declarations
- Normal author declarations
- Normal user declarations
- Normal user agent declarations
Read the normal half from the bottom up: browser defaults, then the user's preferences, then the page's author styles, each overriding the one below. Then read the important half: author, user, browser. The order inverts. That isn't an accident or a historical quirk. Cascade 5 §6.3 says CSS "attempts to create a balance of power between author and user style sheets," and that marking a declaration important "increases its weight in the cascade and inverts the order of precedence." It gives the reason directly: user-origin important declarations override author-origin important ones, and "this CSS feature improves accessibility of documents by giving users with special requirements (large fonts, color combinations, etc.) control over presentation."
So !important isn't really an "I win" flag. It's a way to move a declaration from the bottom half of the list to the top half, where the order of origins runs the other way. An author can't use it to beat a user who also used it. The user agent's own important declarations sit above both, and the spec says they "override all author and user declarations."
Fig. 2 shows the eight levels as a stack, with the inversion happening as the important half builds up above the animation band.
Animations sit in the middle, transitions on top
The position of the animation origin explains a behavior people often discover by accident. A running CSS animation overrides every normal declaration, whatever its origin or specificity. But Cascade 5 §6.3 puts every important declaration above it: "Important declarations from all origins take precedence over animations. This allows authors to override animated values in important cases." Transitions sit above everything, even important user-agent declarations. MDN's cascade introduction describes the same order for readers: animations above normal values, important values above animations, transitions above important values.
In practice that means a !important on a property you also animate silently overrides the animation for that property: the animated value never becomes the cascaded value. If an animation "does nothing", search for !important on the animated property before you look at the keyframes.
Presentational hints get an origin of their own
There's one more origin that §3.1 doesn't list, because it's defined separately. Cascade 5 §6.5 covers styling that comes from markup rather than CSS, like HTML's bgcolor attribute or SVG presentation attributes. All of it "must be translated to corresponding CSS rules and enter the cascade as rules in either the UA-origin or a special-purpose author presentational hint origin between the regular user origin and the author origin."
That placement has a consequence the spec spells out: hints in the author presentational hint origin "can be overridden by author-origin styles, but not by non-important user-origin styles." It also has a quirk. For cascading, the hint origin is independent, but "for the purpose of the revert keyword (but not for the revert-layer keyword) it is considered part of the author origin." So revert in an author style sheet rolls back past presentational hints, and revert-layer doesn't. The rollback keywords get their own note later in this series.
HTML describes the same thing from its side. Its rendering section says some of its rules "are intended for the author-level zero-specificity presentational hints part of the CSS cascade." MDN's cascade introduction puts it differently: it says presentational attributes "do not participate in the cascade", then that they are "translated to the corresponding CSS rules" and "inserted in the author stylesheet prior to any other styles with a specificity equal to 0." Those two sentences describe the same outcome in most cases: author CSS overrides the hint. But the spec's model is a separate origin, not the start of the author sheet, and that's what decides the revert versus revert-layer difference. When MDN and the spec disagree on mechanism, I go with the spec.
Context and the style attribute are settled before layers
Steps 2 and 3 are both about where a declaration is attached rather than what it says: which tree its style sheet lives in, and whether it sits on the element itself. Both are compared before any layer is looked at.
The outer tree sets defaults, the inner tree can enforce them
The second key only matters when declarations come from different shadow trees. Cascade 6 §3.1 says that when two declarations come from different encapsulation contexts, "for normal rules the declaration from the outer context wins, and for important rules the declaration from the inner context wins." Contexts nest "in shadow-including tree order."
The note that follows gives the design intent better than I could: normal declarations in an encapsulation context "can set defaults that are easily overridden by the outer context," while important ones "can enforce requirements that cannot be overridden by the outer context." It's the same inversion as origins, applied to the component boundary. A component author writes :host { display: block; } as a default the page can change. If they write :host { display: block !important; }, the page can't override it, even with its own !important.
<user-card>Ada Lovelace</user-card>
<style>
/* Document context: beats the normal :host rule below */
user-card { color: green; }
</style>
<script type="module">
const root = document.querySelector('user-card')
.attachShadow({ mode: 'open' });
// Shadow context: a default the page can override
root.innerHTML = `
<style>:host { color: red; }</style>
<slot></slot>`;
</script>The card renders green. Change both declarations to !important and it renders red, because the inner context now wins. Specificity plays no part in either outcome: context is decided at step 2, and :host versus user-card would only be compared at step 5.
"Outer" is less obvious than it sounds once there are several shadow trees side by side. The WPT test shadow-cascade-order-001 builds a <my-list> with a shadow tree containing a ::slotted(my-item) rule, and a <my-item> inside it with its own shadow tree containing a :host rule. Neither tree contains the other. The test expects the ::slotted rule to win between the two for normal declarations ("earlier in tree-of-trees rule should win") and the :host rule to win when both are important. So the test reads "outer" as "earlier in shadow-including tree order": <my-list>'s shadow tree comes before <my-item>'s, and it's treated as the outer context. The same file checks that a :host rule with !important beats an important style attribute on the host. All 64 subtests pass in the latest stable runs on wpt.fyi for Chrome 155, Firefox 158 and Safari 27.0 (runs of 17 October 2026).
Two more details belong here. First, layers are scoped to their origin and context: a note in Cascade 5 says the order of layers in the light DOM "has no impact on the order of identically-named layers in the shadow DOM (and vice versa)." A @layer reset inside a component is not the page's reset layer. Second, the CSS Shadow module's section on the cascade (Editor's Draft, 28 April 2026) is one line: it points to the cascade sort. Everything about shadow trees and specificity, ::part() and ::slotted() is styling detail for a later note in this series; the cascade rule itself is the two sentences above.
The style attribute is its own step, not a huge specificity
Step 3 is short. Cascade 6 says that, "separately for normal and important declarations," declarations attached directly to an element, such as a style attribute, take precedence over declarations of the same importance mapped by a style rule.
Most developers learned a different model. The CSS Style Attributes spec still says its declarations "are considered to have author origin and a specificity higher than any selector." MDN's specificity page suggests you "think of inline styles as having a specificity weight of 1-0-0-0." Before layers, that mental model gave the right answer in the cases people ran into. With layers it doesn't, and that's exactly why the step exists. The Changes section of Cascade 6 lists, among additions since Level 4, that cascade layers were added to the sort "and defined style attributes as a distinct step of the cascade sort criteria so that they interact appropriately" (Cascade 6, Changes).
Here's the case that separates the two models:
<style>
@layer reset {
.notice { color: red !important; }
}
</style>
<p class="notice" style="color: green !important">Saved</p>If the style attribute were a very specific unlayered rule, it would sit in the implicit final layer. Important declarations in earlier layers beat important unlayered ones (next section), so the layered red would win. Because the style attribute is compared at step 3, before layers are ever looked at, the paragraph is green. That's the WPT test layer-vs-inline-style case "Important inline style > important layered style," and it's conflict 5 in the quiz below.
The step is also "separately for normal and important," and that is the other half of the story. A normal style="color: red" loses to .notice { color: green !important; } in any layer, because importance was decided at step 1. MDN states it plainly: "The only way to override inline styles is by using !important."
For order of appearance, the style attribute has a fixed place too: Cascade 6 says declarations from style attributes "are ordered according to the document order of the element the style attribute appears on, and are all placed after any style sheets." In practice two style attributes almost never compete for one element, so this mostly matters for completeness.
Unlayered styles sit in a final layer, and !important reverses the order
Step 4 is the only key whose order you write down on purpose. Cascade 6 says declarations "within each origin and context" can be assigned to a cascade layer, and "any declaration not assigned to an explicit layer is added to an implicit final layer." For normal rules, "the declaration whose cascade layer is latest in the layer order wins"; for important rules, "the declaration whose cascade layer is earliest wins." The note after it makes the parallel explicit: this "follows the same logic used for precedence of normal and important origins."
Three consequences follow.
Unlayered styles beat layered ones, regardless of specificity. The implicit layer is last, so for normal declarations it wins every layer comparison. Cascade 5's own example uses audio { display: flex; } unlayered against audio[controls] { display: block; } in a reset layer, and the unlayered rule wins "even though the unlayered styles have a lower specificity, and come first in the order of appearance."
!important reverses the layer order. An !important in your first layer is the strongest author declaration you can write, stronger than an !important outside any layer. If you wrap a third-party library in a layer to tame it and the library uses !important, you've made its important declarations stronger than yours.
Layer order is set by first mention. Layer ordering sorts layers "by the order in which they first are declared, with nested layers grouped within their parent layer," and unlayered rules sort after layered rules in the same parent. So the usual pattern is a statement at the top of the entry style sheet:
/* First mention fixes the order: later layers win normal conflicts */
@layer reset, vendor, components, utilities;
@import url("vendor/datepicker.css") layer(vendor);
@layer reset {
button { font: inherit; }
}A few edge rules from the same section matter in large codebases. A nested framework.base layer is distinct from a top-level base. Unnamed @layer { } blocks each create a separate layer that nothing else can reference. And layers declared inside @media or @supports only contribute to the order when the condition is true, so a media query can change the layer order. The spec's own example shows theme and layout swapping places depending on which query matches, and its advice is to "establish an explicit ordering of layers in advance, and avoid defining new layers inside conditional rules."
There's also an open design question. Issue #6323, "Allow authors to explicitly place unlayered styles in the cascade layer order", was still open on 18 October 2026 and is linked from the Layer Ordering section of the spec. Today, unlayered styles are always last; nothing lets you slot them between two named layers.
Layers have been Baseline widely available since 14 September 2024 and newly available since 14 March 2022, per webstatus.dev, which lists Chrome 99, Firefox 97 and Safari 15.4 as the first supporting versions. Production patterns (wrapping vendors, the !important trap, migrating an existing sheet) are the subject of the next note in this series. Here the point is narrower: layers are compared before specificity, so they're where most "but my selector is more specific" surprises now come from.
Specificity is the fifth question, and it has its own exceptions
If two declarations tie on origin, importance, context, the style attribute and layer, the cascade finally compares selectors. Selectors Level 4 (Editor's Draft, 18 September 2026) counts ID selectors as A; class selectors, attribute selectors and pseudo-classes as B; type selectors and pseudo-elements as C; and ignores the universal selector. Comparison goes A first, then B, then C. Two details in that section are easy to miss: repeated occurrences of the same simple selector "are allowed and do increase specificity" (so .btn.btn is (0,2,0)), and implementations that limit the size of A, B or C must clamp rather than overflow.
The interesting rules are the exceptions:
- The specificity of
:is(),:not()or:has()"is replaced by the specificity of the most specific complex selector in its selector list argument." That's the most specific argument, whether or not it's the one that matched. :nth-child()and:nth-last-child()count as one pseudo-class plus the most specific selector in theirof Sargument.- "The specificity of a
:where()pseudo-class is replaced by zero." - For a rule's own selector list (
h1, #title { }), the specificity "in effect is that of the most specific selector in the list that matches." That one does depend on matching.
The :is() rule is behind one of the conflicts below. :is(.btn, #legacy-buy) has specificity (1,0,0) on every element it matches, including a plain .btn with no ID anywhere near it:
/* (1,0,0) for every match, because #legacy-buy is in the list */
:is(.btn, #legacy-buy) { color: green; }
/* (0,2,0): loses, even though it comes later */
.toolbar .btn { color: red; }MDN's specificity page has a section called "Tree proximity ignorance" that's worth holding in mind for the next step: "The proximity of an element to other elements that are referenced in a given selector has no impact on specificity." body h1 and html h1 tie, and order decides. Specificity measures the selector, never the DOM.
What @scope and :host add to specificity
@scope deliberately adds nothing. Cascade 6 §3.5.1 says selectors inside @scope "do not acquire the specificity of any parent selector(s) in the @scope prelude." Its example gives @scope (#hero) { img { } } and :where(#hero) img { } the same specificity, (0,0,1). Inside a scope, :scope is an ordinary pseudo-class worth (0,1,0), and & now behaves as :where(:scope), worth zero. That last rule is newer than the published draft: the 2024 Working Draft said & represents the <scope-start> selector, and the Editor's Draft's Changes list records "Defined & to behave like :where(:scope)." The WPT file that checks this, including a subtest commented "& behaves like :where(:scope)", passes all 11 subtests in the latest stable Chrome, Firefox and Safari runs.
:host is the odd one out in the other direction. The CSS Shadow module says :host has the specificity of a pseudo-class, and :host() that of a pseudo-class "plus the specificity of its argument." It notes the difference from :is() and :not() explicitly. Nesting has its own specificity rules too, which get a note of their own later in the series.
Scope proximity counts hops, and only breaks specificity ties
Step 6 is the newest key in practice: @scope has been Baseline newly available only since 24 March 2026. webstatus.dev lists Chrome 143, Firefox 146 and Safari 26.4 as its supporting versions. The rule is in Cascade 6 §3.1: when declarations appear in style rules with different scoping roots, "the declaration with the fewest generational or sibling-element hops between the scoping root and the scoped style rule subject wins." Style rules without a scoping root "are considered to have infinite proximity hops."
The classic use is a theme that can nest inside its opposite. Chrome's @scope article (4 October 2023) shows .light a and .dark a without scoping: a link inside .light inside .dark takes whichever rule comes last in the style sheet, because the two selectors tie on specificity. With @scope (.light) { a { } } and @scope (.dark) { a { } }, the link takes the rule from its nearest themed ancestor. Fig. 3 shows the hop count doing that work.
@scope (.dark) {
a { color: plum } }
specificity (0,0,1)
wins: 1 < 3
@scope (.light) {
a { color: darkmagenta } }
specificity (0,0,1)
/* Both rules are (0,0,1). Proximity decides, then order. */
@scope (.dark) { a { color: plum; } }
@scope (.light) { a { color: darkmagenta; } }The WPT scope-proximity test checks the same structure, an alternating light/dark/light/dark nest with two equal-specificity scoped rules, alongside two subtests whose titles state the placement in the sort: "Proximity wins over order of appearance" and "Specificity wins over proximity." All five subtests pass in the latest stable Chrome 155, Firefox 158 and Safari 27.0 runs on wpt.fyi.
One sentence in §3.5.1 says the opposite of §3.1
Here's where the draft contradicts itself. The sort in §3.1 puts specificity before proximity. But §3.5.1, Effects of @scope, says: "The cascade prioritizes declarations with a more proximate scoping root, regardless of specificity or order of appearance by applying scope proximity." Read literally, that's the opposite: proximity beats specificity. Both the 6 September 2024 Working Draft and the 28 April 2026 Editor's Draft contain both texts.
The history explains it. I traced the sentence through the csswg-drafts repository. It was introduced in commit cc730fb on 24 September 2021, the same edit that defined two candidate behaviors, "strong scoping proximity" (weighted above specificity) and "weak scoping proximity" (below it), with an open issue asking which @scope should use. Before that edit, the sentence said only "regardless of source order." So "regardless of specificity" was written to describe strong proximity while strong proximity was still a live option.
Then the Working Group chose. Issue #6790, "Strong vs weak scoping proximity," opened in November 2021. The group first resolved that it "leans towards weak proximity at this time," and on 22 March 2023 resolved: "cascade proximity is weaker than specificity." The issue was closed on 11 December 2023, and the Changes section lists "Removed strong scope proximity." On the same day, commit 429947f, marked editorial, changed "regardless of specificity or source order" to "regardless of specificity or order of appearance". It updated the terminology and left the leftover claim in place.
So my reading is that §3.5.1's "regardless of specificity" is a stale sentence from before the resolution, and §3.1 is the rule. Four independent things support that: the sort order itself, the recorded resolution, the WPT subtest "Specificity wins over proximity" passing in all three stable engines, and conflict 8 below, which I ran myself. Chrome's article agrees too: it says the proximity step "comes after specificity but before order of appearance." A GitHub search of csswg-drafts on 18 October 2026 for the phrase found no issue about the wording, so I can't tell you whether or when it will be fixed.
Proximity is one number, measured from the innermost scope
Two more decisions shape how proximity behaves. The Changes section says the draft "clarified that scope proximity is a single measurement of the steps between a single scoping root and scoped style rule subject." Scope Nesting adds that when @scope rules nest, "only the innermost @scope matters for determining scope proximity." The outer scope narrows where the rule can match, but it doesn't contribute a second number to compare.
Whether nested scopes should compare a list of distances, innermost first, was raised in issue #10795. On 19 August 2025 the group resolved to "Close no change for now, unless someone comes back with clear use cases + proposal," and in the same discussion to republish a Working Draft of Cascade 6. The publication history still showed 6 September 2024 as the latest Working Draft on 18 October 2026, so the published TR copy is now over two years behind the Editor's Draft.
Proximity being weaker than specificity has a practical upshot: it's a tiebreaker for well-behaved component styles, not a weapon. The minutes of the 22 March 2023 discussion record the argument for that choice: when the two heuristics conflict, "specificity is easier to change." If you write low-specificity rules inside scopes, proximity does what you want. If an unscoped .card a from somewhere else in the codebase has higher specificity, proximity will never get a vote. @scope against naming conventions, and what scoping doesn't isolate, are the subject of a later note in this series.
Order of appearance decides last, across files
When everything else ties, the last declaration in document order wins. The spec defines what "document order" means across files: declarations from imported style sheets "are ordered as if their style sheets were substituted in place of the @import rule," and style sheets independently linked by the document "are treated as if they were concatenated in linking order, as determined by the host document language." Style attributes come after all style sheets.
That makes order of appearance the only criterion that depends on how your build concatenates files. Two bundles that contain identical rules in a different order can render differently, but only for declarations that tie on all six earlier keys. Layers were designed so that you stop depending on this: Cascade 5 says they let authors re-order concerns "without altering selectors or specificity within each layer, or relying on order of appearance to resolve conflicts across layers."
One subtlety: layers themselves are sorted by order of appearance (Cascade 6 says so in as many words), but at step 4, with first declaration deciding. A rule late in a file can still sit in an early layer. "Later wins" is only true for declarations in the same layer.
Ten conflicts, each decided by a single row
Each conflict below sets one property two ways. For each, I list the comparator walk: the rows that tie, then the row that decides. I ran all ten as a page that injects each case's CSS and HTML, reads getComputedStyle(el).color, and checks for green. The harness ran under Playwright 1.64.1 on macOS, headless, in four engines: Google Chrome 155.0.8059.80 (stable channel), Chromium 156.0.8078.4, and Playwright's own builds of Firefox 155.0 and WebKit 27.2. Playwright's Firefox and WebKit are patched builds, not the browsers people download, so for shipping Firefox and Safari I rely on the WPT stable results cited above. In every engine, all ten came out green. A negative control (swapping the colors in one case) produced a FAIL, so the harness can tell the difference.
const GREEN = 'rgb(0, 128, 0)';
// Each case: CSS for the document, optional CSS for a shadow root on
// the first element, the markup, and the element to read.
export function check(name, { css, html, shadowCss, pick }) {
const box = document.createElement('div');
const sheet = document.createElement('style');
sheet.textContent = css;
document.head.append(sheet);
box.innerHTML = html;
document.body.append(box);
if (shadowCss) {
const root = box.firstElementChild.attachShadow({ mode: 'open' });
root.innerHTML = `<style>${shadowCss}</style><slot></slot>`;
}
const { color } = getComputedStyle(box.querySelector(pick));
sheet.remove();
box.remove();
return `${color === GREEN ? 'PASS' : 'FAIL'} ${name}`;
}
// Conflict 1 below, as the harness runs it.
console.log(check('1. layered ID vs unlayered type', {
css: `@layer components { #site-nav a { color: red; } }
a { color: green; }`,
html: '<nav id="site-nav"><a href="/">Home</a></nav>',
pick: 'a',
}));Load it as a module (<script type="module" src="cascade-quiz.js">) in an otherwise empty page; the other nine cases are the snippets below, each with the markup given under it.
1. A layered ID selector against an unlayered type selector
@layer components {
#site-nav a { color: red; }
}
a { color: green; }Markup: <nav id="site-nav"><a href="/">Home</a></nav>. Origin and importance tie (normal author). Context ties (document). Neither is a style attribute. Layers decide: a is in the implicit final layer, which is latest. The (1,0,1) selector never gets to use its ID. Green.
2. A layered !important against an unlayered ID
@layer reset {
.muted { color: green !important; }
}
#promo.muted { color: red; }Markup: <p id="promo" class="muted">Sale</p>. Origin and importance decide at the first row: important author beats normal author. Layers would favor the unlayered rule, but they're never consulted. Green.
3. !important in the first layer against !important unlayered
@layer reset, components;
@layer reset { .btn { color: green !important; } }
@layer components { .btn { color: red !important; } }
#checkout .btn { color: red !important; }Markup: <div id="checkout"><button class="btn">Pay</button></div>. All three are important author declarations in the document, none from a style attribute. Layers decide, in reverse: for important rules the earliest layer wins, so reset beats components, and both beat the implicit final layer where the (1,1,0) selector sits. Green.
4. A normal style attribute against an !important rule
<style>.notice { color: green !important; }</style>
<p class="notice" style="color: red">Hi</p>Origin and importance decide: important author beats normal author. The style attribute row is "separately for normal and important," so it never compares these two. Green.
5. An !important style attribute against !important in the first layer
<style>
@layer reset { .notice { color: red !important; } }
</style>
<p class="notice" style="color: green !important">Hi</p>Origin and importance tie (important author). Context ties. The style attribute decides at row 3, before layers are asked. This is the case the 1-0-0-0 mental model gets wrong. Green.
6. A document rule against :host
/* Document */
user-card { color: green; }
/* Inside user-card's shadow root */
:host { color: red; }Origin and importance tie (normal author). Context decides: for normal rules the outer context wins. Green.
7. The same pair, both !important
/* Document */
user-card { color: red !important; }
/* Inside user-card's shadow root */
:host { color: green !important; }Context decides again, inverted: for important rules the inner context wins. The component enforces its value. Green.
8. A scoped type selector against an unscoped class and type
.card a { color: green; }
@scope (.card) {
a { color: red; }
}Markup: <div class="card"><a href="/">Read</a></div>. Rows 1 to 4 tie: same origin, importance, context and implicit layer, and neither is a style attribute. Specificity decides: (0,1,1) beats (0,0,1), because the .card in the @scope prelude adds nothing. The scoped rule is 1 hop from its root and the unscoped one is infinitely far, but proximity is never consulted. Green. This is the case that settles §3.5.1.
9. A scoped rule against a later unscoped rule of equal specificity
@scope (.card) {
a { color: green; }
}
a { color: red; }Same markup. Rows 1 to 5 tie, including specificity at (0,0,1). Scope proximity decides: 1 hop beats infinite hops, so the earlier, scoped rule wins over the later, unscoped one. Green.
10. :is() with an ID against two classes that come later
:is(.btn, #legacy-buy) { color: green; }
.toolbar .btn { color: red; }Markup: <div class="toolbar"><button class="btn">Buy</button></div>. Rows 1 to 4 tie. Specificity decides: :is() takes its most specific argument, (1,0,0), even though the button matched through .btn. (1,0,0) beats (0,2,0), so order of appearance never gets a say. Green.
Two cases are worth adding that I didn't put in the harness, because they're already in the spec's own examples. Cascade 5's importance example shows a user's p { font-size: 18pt } losing to an author's p { font: normal 12pt sans-serif !important }: a normal user declaration against an important author shorthand. And its layering example shows @keyframes with the same name resolving by layer order too, since at-rules defined inside layers "also use the layer order when resolving collisions."
Debug in comparator order, and design so the early rows decide
The practical value of knowing the order is that it tells you which question to ask first. When a declaration doesn't apply, I'd go down the rows in this order, and stop at the first one that differs:
- Did it survive filtering? An invalid value or unknown property is dropped before the cascade. Check that the declaration appears as valid at all.
- Origin and importance. Is anything
!importanton this property? Is an animation or transition running on it? An!importantanywhere in the chain changes which half of the origin list you're in. - Context. Is the element a shadow host, or slotted into one? Normal page styles beat normal
:hoststyles; important:hoststyles beat everything the page can write. - Style attribute. Is something, often a framework, writing
style=""? Only!importantbeats a normal one, and no author style sheet in the same context beats an important one. - Layers. Which layer is each declaration in, and where is that layer in the order? Unlayered beats layered for normal declarations; for
!important, the first layer wins. - Specificity. Only now count IDs and classes, remembering
:is()and:where(). - Scope proximity, then order of appearance.
For design, the order points the same way. Decide things as high in the comparator as you can, because high rows are explicit and low rows are accidental. Layers are explicit: you write the order down once. Specificity is semi-accidental: it depends on how selectors happen to be written. Order of appearance is fully accidental: it depends on your bundler. My recommendations, as of October 2026:
- Put every style sheet you don't control into a layer early in the order, and declare the order in one
@layerstatement at the top of your entry sheet. Layers have been widely available for over two years. - Treat
!importantas a tool for the first layer only, for the few declarations that must never be overridden (the[hidden] { display: none !important; }that Cascade 5 uses as its example is a good one). Anywhere else it fights the layer order you designed. - Write low-specificity selectors inside components, using
:where()where you need structure without weight, so that layers and then proximity decide conflicts instead of selector arithmetic. - Use
@scopefor proximity between components that nest, but don't expect it to beat a more specific selector elsewhere. It's a tiebreaker after specificity, whatever §3.5.1 currently says. - In components, use normal
:hostrules for defaults and!importantonly for what the page must not change.
What we don't know
- Whether §3.5.1 will be corrected. The "regardless of specificity" sentence predates the March 2023 resolution, and every engine I tested follows §3.1. I found no CSSWG issue about it on 18 October 2026. A spec edit or a filed issue would settle it; until then, a reader of the spec alone could reasonably come away with the wrong order.
- When Cascade 6 will be republished. The group resolved on 19 August 2025 to republish a Working Draft. Fourteen months later the latest TR copy is still 6 September 2024, which predates the
&change, declarations directly inside@scope, and@import scope(), all listed in the Editor's Draft's Changes. Anyone reading only the TR copy gets an outdated&specificity rule. - What a "sibling-element hop" is for. §3.1 counts "generational or sibling-element hops," but a scoped rule's subject must be an inclusive descendant of its scoping root, and every example in the draft counts only generations. I couldn't find a case in the current syntax where a sibling hop applies, or text explaining why the phrase is there.
- Whether nested scopes will ever weigh more than the innermost root. Issue #10795 closed with "no change for now", explicitly open to a future proposal with use cases.
- Two cross-references that point at the wrong place. Cascade 6's §3.6 on presentational hints is a placeholder that links to Cascade 5's Cascade Layers section rather than its presentational-hints section, and the CSS Shadow module's cascade section points to Cascade 4's sort, which has no layers. I read both as editorial slips, but I haven't seen either confirmed.
- MDN's description of presentational attributes. MDN says they "do not participate in the cascade" and are inserted at the start of the author sheet; the spec gives them their own origin, which is what makes
revertandrevert-layertreat them differently. I didn't test how engines handlerevert-layeragainst a presentational hint, so I can't say which description matches shipping behavior in that corner. - How engines date
@scope. webstatus.dev lists Chrome 143 as the version that completes@scope, while the support table in Chrome's October 2023 article shows 118. My guess is that web-features counts later parts of the feature, such as the&change, but I didn't trace the compat keys to confirm it. - The limits of my own test run. I ran ten cases, headless, in Playwright's Firefox and WebKit builds rather than shipping Firefox and Safari, and on one machine. The WPT stable results cover the same rules in shipping browsers, but not my exact snippets. I also didn't test the user origin, which depends on each browser's way of supplying user style sheets.
References
- CSS Cascading and Inheritance Level 6 - Editor's Draft, 28 April 2026 (Cascade Sorting Order). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 6 - Editor's Draft (Effects of @scope). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 6 - Editor's Draft (Scope Nesting). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 6 - Editor's Draft (Changes). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 6 - Editor's Draft (Precedence of Non-CSS Presentational Hints). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 6 - W3C Working Draft, 6 September 2024. W3C>. Accessed .
- CSS Cascading and Inheritance Level 6 publication history. W3C>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft, 13 April 2026 (Cascade Sorting Order). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Filtering). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Cascading Origins). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Important Declarations). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Cascade Layers). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Layer Ordering). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Editor's Draft (Precedence of Non-CSS Presentational Hints). CSS Working Group>. Accessed .
- CSS Cascading and Inheritance Level 5 - Candidate Recommendation Snapshot, 13 January 2022. W3C>. Accessed .
- CSS current work and how to participate. W3C>. Accessed .
- CSS Shadow Module Level 1 - Editor's Draft, 28 April 2026 (Shadow Trees and the Cascade). CSS Working Group>. Accessed .
- CSS Shadow Module Level 1 - Editor's Draft (:host, :host() and :host-context()). CSS Working Group>. Accessed .
- CSS Style Attributes - Editor's Draft (Cascading and Interpretation). CSS Working Group>. Accessed .
- Selectors Level 4 - Editor's Draft, 18 September 2026 (Calculating a selector's specificity). CSS Working Group>. Accessed .
- HTML Standard - The CSS user agent style sheet and presentational hints. WHATWG>. Accessed .
- Introduction to the CSS cascade. MDN>. Accessed .
- Specificity. MDN>. Accessed .
- Cascade layers - Web Platform Status. Web Platform Status (webstatus.dev)>. Accessed .
- @scope - Web Platform Status. Web Platform Status (webstatus.dev)>. Accessed .
- Limit the reach of your selectors with the CSS @scope at-rule. Chrome for Developers>. Accessed .
- csswg-drafts #6790: [css-cascade-6] Strong vs weak scoping proximity. CSS Working Group (GitHub)>. Accessed .
- csswg-drafts #6790: resolution of 22 March 2023, "cascade proximity is weaker than specificity". CSS Working Group (GitHub)>. Accessed .
- csswg-drafts #10795: [css-cascade-6] Should the scope proximity calculation be impacted by nesting scopes?. CSS Working Group (GitHub)>. Accessed .
- csswg-drafts #10795: resolution of 19 August 2025. CSS Working Group (GitHub)>. Accessed .
- csswg-drafts #6323: [css-cascade-5] Allow authors to explicitly place unlayered styles in the cascade layer order. CSS Working Group (GitHub)>. Accessed .
- csswg-drafts commit cc730fb: [css-cascade-6] Incorporate ideas from this week's discussions (24 September 2021). CSS Working Group (GitHub)>. Accessed .
- csswg-drafts commit 429947f: [css-cascade-6][editorial] Replace source order with order of appearance (11 December 2023). CSS Working Group (GitHub)>. Accessed .
- WPT css/css-cascade/scope-proximity.html (source). web-platform-tests>. Accessed .
- WPT css/css-cascade/scope-proximity.html (stable results). wpt.fyi>. Accessed .
- WPT css/css-cascade/scope-specificity.html (stable results). wpt.fyi>. Accessed .
- WPT css/css-cascade/layer-vs-inline-style.html (source). web-platform-tests>. Accessed .
- WPT css/css-shadow/shadow-cascade-order-001.html (source). web-platform-tests>. Accessed .
- WPT css/css-shadow/shadow-cascade-order-001.html (stable results). wpt.fyi>. Accessed .