Recommended Free Tools
CSS’s @scope at-rule limits where enclosed selectors can match: a scope root marks the top of a DOM subtree, and an optional scope limit marks where matching stops. It can keep component styles from reaching selected nested content without requiring a unique class on every descendant. It also adds scoping proximity as a separate factor in the cascade.
What does @scope do?
A normal selector can match anywhere in the document that satisfies its conditions. Rules inside @scope are instead restricted to a bounded subtree. The W3C describes scoped style rules as applying “only within a subtree of a document, rather than matching against the entire document” (CSS Scoping Module Level 1).
As an Amazon Associate I earn from qualifying purchases.
This is a way to limit selector matching, not a way to rename selectors or automatically isolate a component completely. It is not a security boundary; it addresses where the enclosed style rules can match.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →How do I scope CSS to a component?
Put the component’s root selector in the @scope prelude, then place the selectors to restrict inside its braces:
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
@scope (.article-body) {
img {
border: 5px solid black;
}
}
Here, .article-body is the scope root. The img rule can match images within that root’s subtree, including the root itself if it matches the enclosed selector. The root is included in the scope.
You can also write @scope without a prelude inside a <style> element. In that form, the scope is the style element’s enclosing parent. Root and limit preludes can use selector lists to define multiple scopes. See MDN’s @scope reference for the syntax and details.
Rank #2
How do I stop styles from affecting nested content?
Add a limit after to. Matching stops at that limit, which is excluded from the scope. This pattern is sometimes called a donut scope: it styles within the outer boundary while leaving a selected nested region out.
@scope (.article-body) to (figure) {
img {
border: 5px solid black;
}
}
In this example, the rule can match images inside .article-body, but not images inside a figure within that scope. The figure limit itself is excluded, along with its descendants. This is useful when a component contains a nested area—such as an embedded figure—that should not inherit the component’s matching rules.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
How does scope proximity affect the cascade?
@scope adds scoping proximity to cascade resolution. When declarations are otherwise tied on the relevant cascade criteria, the declaration whose scope root is nearer to the styled element can win before specificity is used to break the tie. Proximity and specificity are distinct; @scope does not simply make a selector more or less specific. The W3C explains the cascade rules in CSS Cascading and Inheritance Level 6.
Within an @scope block, MDN says bare selectors and the nesting selector & behave as though :where(:scope) were prepended, adding zero specificity. An explicit :scope selector contributes pseudo-class specificity. MDN also notes that browser engines and releases have differed in how & is handled, so check current compatibility information before relying on edge cases.
Rank #4
What is the difference between @scope and :scope?
@scope is an at-rule that establishes the region in which style rules can match. :scope is a pseudo-class that represents a reference element, and what it refers to depends on where it is used:
- Inside an
@scopeblock,:scopematches that block’s scope root. - At the root of a stylesheet, it corresponds to the document root.
- In DOM query methods, it matches the element on which the method was called.
MDN documents these contexts in its :scope reference.
Best Value
Is @scope supported in browsers?
MDN marks @scope Baseline 2026 and says it has been newly available across the latest browser versions since March 2026. That status does not guarantee support in older browser versions or on every device. Check the current compatibility information against the browsers your project needs to support; the cited reference does not provide a complete version-by-version minimums table.
If older browsers are in scope, treat @scope as a compatibility decision rather than assuming it works everywhere. Other approaches, such as component naming conventions or global selectors, have different trade-offs: a scope limit can stop matching at a nested boundary, while broader isolation needs may require a separate encapsulation mechanism.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches




