Workflow Intermediate

Controlling specificity without !important

The old way was stacking more specific selectors or throwing !important. @layer lets you decide order without fighting specificity.

Modern
4 lines
1@layer base, components, utilities;
2
3@layer utilities {
4  .mt-4 { margin-top: 1rem; }
5}
Old Specificity wars
1.card .title { font-size: 1rem; }
2.page .card .title { font-size: 1.25rem; }
3.page .card .title.special { color: red !important; }
4// More selectors or !important to win
Widely available Since 2022 95% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2022.

99+
97+
15.4+
99+
layers control which style wins
@layer base β€” lowest priority
@layer components β€” overrides base
@layer utilities β€” wins, no !important
@layer base, components, utilities;
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more
⚑

Order over specificity

Later layers win. No need to make selectors more specific to override.

✦

Predictable cascade

base, then components, then utilities. Same order every time.

∞

No !important

Utilities can override components with a single class. Clean and explicit.

Lines Saved
N/A
Clear structure
Old Approach
!important, specificity
Selector arms race
Modern Approach
@layer order
Declared priority

How it works

Previously you made selectors more specific (e.g. .page .card .title) or used !important to force overrides. That led to specificity wars and hard-to-debug styles.

@layer base, components, utilities defines the order. Whatever comes later wins when specificity is equal. Put resets in base, components in components, and utility classes in utilities. No !important, no long selectors.

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC