CSS · Layout and visual systems
How do cascade layers work?
Short answer
Cascade layers let you declare explicit priority between groups of styles. Layer order is set first, and for normal declarations a later layer wins; unlayered styles beat layered ones, and importance reverses the order.
The @layer rule creates named layers. Their order is established the first time they are declared, not by where individual rules appear later. That gives you control over the cascade without inflating specificity.
@layer reset, base, components, utilities;
@layer base {
a {
color: blue;
}
}
@layer components {
.button {
color: white;
}
}The rules
- Layer order is determined by first declaration of each layer
- For normal declarations, later layers override earlier layers
- Unlayered normal declarations override all layered normal declarations
- For important declarations, the order reverses: earlier layers win
- Nested layers are scoped inside their parent layer
- Layers do not replace specificity; they sit above it in the cascade
Layers are useful for resets, third-party CSS, component libraries and utilities. You can put a vendor stylesheet in a low-priority layer and override it with your own component layer without writing more specific selectors.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What wins between a layered and an unlayered normal declaration?
- 2How does importance change layer order?
- 3How is layer order determined?
- 4When would you use cascade layers instead of specificity?
Say it in the interview
Cascade layers let me define groups with explicit priority before any rules are evaluated. For normal declarations, later layers win, and unlayered styles beat layered ones. For important declarations the order reverses. Layers sit above specificity in the cascade, so they are a better architectural tool than escalating selectors, and I use them for resets, vendor CSS, components and utilities.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CSS mock interview and get scored feedback on depth, clarity and confidence.