Cascade layers are a CSS feature that lets authors group style rules into named, explicitly ordered layers, so that the order of the layers decides which declarations win before selector specificity is even considered. Defined in the CSS Cascading and Inheritance Level 5 specification and introduced through the @layer at-rule, cascade layers give large stylesheets an architectural backbone that does not depend on selector tricks or source order.
In web development, layers address a long-standing problem: resets, frameworks, component libraries and utility classes all compete in one cascade, and teams have historically resolved conflicts with ever-longer selectors or important flags. With layers, the author states the intended priority once, for example @layer reset, base, components, utilities;, and the browser enforces it.
Where cascade layers sit in the cascade
Cascade layers form a dedicated step in the CSS cascade, evaluated after origin and importance but before specificity and order of appearance. When two declarations target the same property on the same element, the browser compares them criterion by criterion and stops at the first one that differs. Because layer order is checked before specificity, a simple class selector in a later layer beats a complex ID selector in an earlier layer.
The table below lists the cascade criteria in the order the browser applies them for normal declarations.
| Step | Criterion | What it compares |
|---|---|---|
| 1 | Origin and importance | User agent, user and author styles, normal or important |
| 2 | Context | Shadow DOM encapsulation versus the outer tree |
| 3 | Element-attached styles | Inline style attribute versus stylesheet rules |
| 4 | Cascade layers | Position of the layer in the declared order |
| 5 | Specificity | Weight of the selector |
| 6 | Order of appearance | Which declaration comes last in the source |
Styles that are not placed in any layer belong to an implicit unlayered group, which is treated as the final and therefore strongest layer for normal declarations. This design lets existing code keep working: legacy, unlayered CSS automatically overrides anything that has been moved into layers.
Declaring and populating layers
Layers are created with the @layer at-rule, and the first mention of a layer name fixes its position in the order. A statement such as @layer reset, base, components; placed at the top of the main stylesheet establishes the full priority list before any rules appear, which is the recommended practice.
Rules can then be added to a layer in a block, in several separate blocks across files, or by importing a whole stylesheet with @import url(theme.css) layer(theme);. Layers can also be nested, producing dotted names such as framework.components, and an @layer block without a name creates an anonymous layer that cannot be appended to later.
| Syntax | Effect | Typical use |
|---|---|---|
| @layer a, b, c; | Declares order without adding rules | Top of the entry stylesheet |
| @layer name { … } | Adds rules to a named layer | Component or module files |
| @import … layer(name) | Places an entire file in a layer | Third-party frameworks and resets |
| @layer outer.inner | Targets a nested sublayer | Internal structure of a library |
| @layer { … } | Creates an anonymous layer | Isolating one-off overrides |
Inside a nested layer, sublayers are ordered relative to each other, while the parent layer as a whole keeps its position among its siblings. Unlayered rules inside a parent layer outrank that parent’s own sublayers, mirroring the top-level behavior.
Important declarations reverse the layer order
For declarations marked as important, the layer order is inverted: an important declaration in the earliest layer beats an important declaration in a later layer or in unlayered styles. This reversal is intentional and follows the same logic as the origin cascade, where important user styles beat important author styles.
The practical consequence is that a reset or base layer can protect a critical rule with the important flag, and no later layer can override it without also changing the layer order. Teams should therefore reserve the important flag for genuine invariants, such as accessibility settings, and not use it as a general escape hatch.
| Declaration source | Normal priority | Important priority |
|---|---|---|
| First declared layer | Lowest | Highest among layers |
| Middle layer | Medium | Medium |
| Last declared layer | High | Low |
| Unlayered author styles | Highest | Lowest among author styles |
Cascade layers compared with related techniques
Cascade layers solve a problem that other CSS methods only work around. Naming conventions such as BEM keep specificity flat by discipline, scoping through Shadow DOM or the @scope rule limits which elements a rule can reach, and specificity hacks inflate selectors to force wins. Layers instead change how conflicts are resolved, and they combine well with the other approaches.
| Technique | Mechanism | Main limitation |
|---|---|---|
| Cascade layers | Explicit priority between groups of rules | Requires an agreed layer plan |
| Specificity management | Selector weight decides conflicts | Escalates into fragile selectors |
| BEM naming | Flat single-class selectors by convention | Relies on team discipline only |
| @scope and Shadow DOM | Limits the reach of rules | Does not order competing sources |
| Important flag | Jumps to the important cascade | Creates hard-to-override rules |
Layers do not replace specificity: within a single layer, specificity and source order still decide as before. A healthy architecture uses layers for broad ordering and keeps selectors simple inside each layer.
Practical adoption and common pitfalls
Cascade layers are supported in all major evergreen browsers since 2022, so most projects can adopt them without a build step. A common plan is reset, base, vendor, components, utilities, with utilities last so that single-purpose classes reliably override component defaults.
- Forgetting the order statement lets file loading order define layer priority, which breaks when bundling changes.
- Leaving legacy CSS unlayered means it silently overrides every layer, which surprises teams during migration.
- Wrapping a framework in a layer is effective, but its own important rules then become harder to override.
- Overusing nested layers adds complexity without benefit; two levels are usually enough.
- Expecting layers to affect inheritance is a misconception, because inherited values are not cascade conflicts.
Browser developer tools display the layer of each matched rule, which makes debugging straightforward. When a rule appears to lose despite a higher specificity, checking the layer label first usually reveals the cause within seconds.
Put simply
A website usually mixes styles from several places: a basic reset, a design system, a downloaded framework and small helper classes. When two of them disagree about a color or a margin, the browser needs a rule to decide who wins.
Cascade layers work like a ranked list of shelves. The author decides in advance which shelf is more important, and the browser respects that ranking. A later shelf always wins, no matter how cleverly an earlier rule was written, which keeps large style sheets predictable.
In practice
A product team maintains a web application that loads a third-party component library alongside its own design system. Over several years, developers had added long selectors and dozens of important flags to override the library, and every library update broke part of the interface.
During a refactor, the team adds @layer reset, library, tokens, components, utilities; to the entry stylesheet and imports the vendor file with layer(library). Their own component styles move into the components layer, and helper classes such as spacing utilities go into utilities. Most of the important flags can then be deleted, because layer order alone guarantees that the team’s styles beat the library.
The result is a stylesheet in which selectors become shorter and the next library upgrade changes only the library layer. Code reviews also become simpler, because any developer can see from the order statement which group of rules is meant to win.