@scope
The @scope CSS at-rule enables you to select elements in specific DOM subtrees, targeting elements precisely without writing overly-specific selectors that are hard to override, and without coupling your selectors too tightly to the DOM structure.
In JavaScript, @scope can be accessed via the CSS object model interface CSSScopeRule.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 118 | 118 | 146 | 17.4 | 118 | 17.4 | |
| DOM API | ||||||
| The CSSScopeRule interface of the CSS Object Model represents a CSS @scope at-rule. | 118 | 118 | 146 | 17.4 | 118 | 17.4 |
| The end property of the CSSScopeRule interface returns a string containing the value of the @scope at-rule's scope limit. | 118 | 118 | 146 | 17.4 | 118 | 17.4 |
| The start property of the CSSScopeRule interface returns a string containing the value of the @scope at-rule's scope root. | 118 | 118 | 146 | 17.4 | 118 | 17.4 |
| CSS selector | ||||||
at-scope `&` treated as `:where(:scope)` in `@scope` blocks | 143 | 143 | 142 | 26.2 | 143 | 26.2 |
Syntax
@scope (.card) to (.card-footer) {
p {
color: #4b5563;
line-height: 1.6;
}
a {
color: #2563eb;
text-decoration: underline;
}
}
/* Inline scope */
@scope (.sidebar) {
:scope {
background: #f8fafc;
padding: 1rem;
}
nav a {
display: block;
padding: 4px 0;
}
} Live demo
Use cases
-
Maintainable CSS architecture
Use @scope to make stylesheet intent clearer in larger codebases and shared design systems.
-
Fallback management
Control resets, imports, inheritance, or feature branches with explicit CSS rules instead of ad hoc duplication.
Cautions
- Cascade-level tools are powerful, so misuse can make style ownership harder to understand.
- Keep rules scoped and documented when they affect many selectors or entire stylesheets.
Accessibility
- Global CSS controls should not accidentally remove focus, contrast, or structural cues.
- Fallback paths should remain readable and functional, especially for assistive-technology users.