CSS @scope At-Rule

Beginner
3 examples
Updated: Nov 2026

Definition and Usage

The @scope at-rule limits where selectors apply. Put a root (and optional lower boundary) around rules so they only match inside that subtree.

CSS Syntax

syntax.css
@scope (.card) {
  h2 { font-size: 1.1rem; }
  img { border-radius: 8px; }
}

Key Parts

PartPurposeTry it
rootSubtree that owns the scoped rulesTry it
to lowerOptional lower boundary that stops matchingTry it
:scopeSelect the scope root from inside the blockTry it

CSS Examples

Scope a card

example.css
@scope (.card) {
  :scope { padding: 1rem; border: 1px solid #cbd5e1; }
  h2 { margin: 0 0 .5rem; }
}
Try It Yourself

Donutscope with lower boundary

example.css
@scope (.article) to (.widget) {
  p { line-height: 1.6; }
}
Try It Yourself

Browser Support

@scope is a modern CSS at-rule.

✓ Modern CSS

@scope

Check current browsers before relying on advanced behavior.

90% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
@scope Modern support

Bottom line: Use progressive enhancement. Keep a readable fallback when a browser ignores the at-rule.

Frequently Asked Questions

It keeps component selectors local without inventing unique class names for every tag.
No. Shadow DOM isolates DOM and styles. @scope only limits selector matching in the light DOM.
A selector that ends the scope so nested widgets are not styled by the outer rules.
Yes. Nested scopes create smaller local regions.
Supported in current Chromium, Safari, and Firefox.

Next: @starting-style

Continue with @starting-style.

@starting-style tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful