Workflow Advanced

Scoped styles without BEM naming

To avoid leaks you used BEM, CSS Modules, or styled-components. @scope limits selectors to a root and optional boundary so you can use short names safely.

Modern
8 lines
1@scope (.card) {
2  .title {
3    font-size: 1.25rem;
4    margin-bottom: 0.5rem;
5  }
6  .body { color: #444; }
7}
8/* HTML: class="card", class="title" */
Old 8 lines
1/* BEM: long names to avoid collisions */
2.card__title {
3  font-size: 1.25rem;
4  margin-bottom: 0.5rem;
5}
6.card__body { color: #444; }
7/* HTML: class="card__title" */
Newly available Since 2024 84% global usage

Since 2024 this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Works in all modern browsers. May need a fallback for older browsers.

118+
128+
17.4+
118+
styles scoped to the card only

Inside @scope

These styles only apply here.

Outside @scope

Same class names, no style leak.

Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more
⚑

Short names

Use .title and .body. They only apply inside the scoped root, so no collisions.

✦

No build

No CSS Modules hash or styled-components runtime. Plain CSS, native in the browser.

∞

Boundary

Optional to (.root) to (.boundary) so inner components don't get styled by outer scope.

Lines Saved
Same lines, less naming
No BEM prefix
Old Approach
BEM or CSS-in-JS
Long names or build step
Modern Approach
@scope
Native scoping

How it works

Global CSS meant long class names (BEM like .card__title) or a system that generated unique names (CSS Modules, styled-components). The goal was to avoid one component's .title affecting another.

@scope (.card) { .title { Ò€¦ } } makes .title only match elements inside a .card. You can use simple class names and keep styles local. Add a boundary with @scope (.panel) to (.slot) so the scope doesn't cross into nested components that should stay independent.

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC