Cascade layers add a step to the cascade that is checked before specificity. When two declarations conflict, the one in the later layer wins regardless of selector specificity. Specificity only decides ties within the same layer. So you can declare an explicit order such as @layer reset, base, vendor, components, utilities; and stop fighting specificity wars with !important and ever-longer selectors. Two rules to remember: unlayered styles beat all layered styles (for normal declarations), and !important reverses layer order. Cascade layers have been Baseline in all major browsers since 2022.
!important)style="")/* Declare the order once, up front. First listed = lowest priority */
@layer reset, base, vendor, components, utilities;
@import url("normalize.css") layer(reset);
@import url("datepicker.css") layer(vendor); /* tame a third-party library */
@layer base {
a { color: var(--link); }
}
@layer components {
.nav a { color: inherit; } /* beats base, as expected */
}
@layer utilities {
.text-danger { color: red; } /* (0,1,0) beats #main .nav a in components */
}
@layer components.forms) and appended to from multiple files. Order is set at first mention, so the up-front declaration statement is the source of truth.@layer { … }) can't be appended to later. Useful for isolating a block.revert-layer rolls a property back to the value from the previous layer.1. Unlayered styles win. Any CSS not in a layer is treated as an implicit final layer. A legacy global stylesheet, or a library you didn't wrap, overrides everything layered, even with weaker selectors. During migration that's a feature (old CSS keeps working). Long-term, put everything in layers, or deliberately leave only overrides unlayered.
2. !important inverts the order.
For important declarations, earlier layers win: reset !important beats utilities !important. This is intentional: it lets a low layer (e.g. accessibility-critical reset rules) protect itself. But it surprises people who use !important in utilities. With layers you rarely need !important at all.
overrides layer, so consumers can customise without !important.:where() for zero-specificity base styles and @scope (supported in Chromium and Safari, and in Firefox more recently) for proximity-based scoping.!important inversion.Spotted a mistake or a rights concern? Report an issue