Selectors and the cascade

Cascade layers

Widely availablesince Sept 2024

Replaces: Specificity escalation and !important. Layers decide which stylesheet wins before specificity is consulted, so a reset can never beat a component.

See it working

The syntax

@layer reset, components, utilities;

@layer components { .btn { background: black; } }
@layer utilities  { .bg-brand { background: blue; } }
Edit the demo’s CSS

This is the stylesheet running the demo above. Change a value and watch it. Break it on purpose: delete the modern line and you are looking at the fallback.

For browsers without it

A browser without it ignores the whole @layer block, so do not put anything inside layers that the page cannot live without unless you have checked your audience.