Cascade Layers
Last updated:
Layer order should control CSS precedence intentionally — not selector escalation wars.
01 — Purpose
Predictable CSS ordering
Cascade layers reduce specificity wars — layer order should control precedence, not selector escalation.
Without layers, teams fight with ever-longer selectors and !important.@layer lets you declare precedence once so overrides stay intentional and readable.
This site uses LSCSS — seeCSS standard and CSS architecture for how layers fit the wider system.
02 — Principles
Order beats escalation
Declare layer order intentionally — then place files in the right layer.
- keep normal declarations layered — unlayered normal rules take precedence over layered normal rules
- later layers win for normal declarations;
!importantreverses layer order, so document any exception - avoid fighting layers with specificity — if you need to, the layer order is wrong
03 — Structure
Layer order on this site
Match the order declared in your entry file — on Frontend Foundations:
legacy— vendor CSS, old frameworks, third-party sheets (sometimes calledthirdpartyin other LSCSS setups)settings— tokens, fonts, breakpointsbase— reset, typography defaultsutilities— single-purpose helperslayout— page shell, containerscomponents— UI blockstheme— colour and theme overrideshacks— documented exceptions only
@layer legacy, settings, base, utilities, layout, components, theme, hacks;
@import './legacy/vendor.css' layer(legacy);
@import './settings/tokens.css' layer(settings);
@import './components/card.css' layer(components);04 — Benefits
What layers buy you
Less !important, clearer overrides, safer scaling.
- predictable overrides — in this stack, normal component rules take precedence over normal utility rules without specificity hacks
- reduced
!importantusage across the codebase - clearer ownership — new files land in the right folder and layer
- safer third-party CSS — isolate vendor styles in the
legacylayer until migrated
05 — Close
Reduce conflict, not add ceremony
Layers should simplify decisions — if the layer list grows past comprehension, simplify the system.
Start with a small, documented layer stack. Add layers when you have a recurring conflict pattern — not preemptively for every folder.
Choose the right rollback boundary
revert-layer rolls a property back to the preceding cascade layer. revert-rule excludes the current style rule when resolving that property. They solve different problems; substituting one for the other can change the result.
Support checked 4 October 2026: revert-rule reached Baseline Newly available with Safari 27. Read the keyword's cascade rules before using it. Supply an explicit usable value for older browsers and gate enhancements with @supports (color: revert-rule)when needed. Prefer simplifying conflicting rules when rollback would make the component harder to understand.
Related: design tokens, container queries.