Cascade Layers
suggest changeCascade layers make precedence between groups of author rules explicit:
@layer reset, base, components, utilities;
@layer base {
a {
color: var(--link-color);
}
}
@layer components {
.button {
color: white;
background: royalblue;
}
}
@layer utilities {
.visually-hidden {
position: absolute;
inline-size: 1px;
block-size: 1px;
overflow: clip;
clip-path: inset(50%);
}
}
For normal declarations, a declaration in a later layer wins over one in an earlier layer before selector specificity is compared. Unlayered author styles have priority over normal declarations inside layers, so establish a layer policy deliberately.
Layers reduce the need for escalating specificity or browser-targeting hacks.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents