Scope component styles with @scope
@scope (.card) to (.card-content) keeps a card's img and p rules out of the HTML slotted inside it, without raising specificity.
Your card styles its author avatar with .card img and its byline with .card p. The card also renders a post body from a CMS, and the first photo in that body shows up as a 48 px circle.
Why the card rules leak
The descendant selector .card img matches images at any depth under .card, including the ones in the CMS slot.
<article class="card">
<img class="avatar" src="ana.jpg" alt="">
<p class="byline">Ana Lima</p>
<div class="card-content">
<p class="body">Text from the CMS</p>
<img class="photo" src="harbour.jpg" alt="Boats in a harbour">
</div>
</article>With .card img { width: 48px; border-radius: 50% } in the stylesheet, both the avatar and the photo get the same size and radius.
Stop the scope at the content slot
@scope takes a root and an optional limit. Rules inside the block match from the root down and stop at the limit.
@scope (.card) to (.card-content) {
img { width: 48px; height: 48px; border-radius: 50%; }
p { color: rgb(110, 110, 110); font-size: 14px; }
}The avatar and the byline keep their styles, and the photo and the CMS paragraph render with their own.
The upper bound is inclusive and the lower bound exclusive. .card-content itself and everything inside it sit outside the scope. MDN calls this shape a donut scope.
diagram
Where @scope (.card) to (.card-content) applies
A card nested inside the content is a new scope root. Its own avatar gets the 48 px circle. Inherited properties can still reach beyond the limit. For example, set color on the card root and paragraphs inside the slot can inherit it.
@scope reached Baseline Newly Available in March 2026, according to the web-features data.
Specificity stays low, proximity breaks ties
@scope adds no specificity. The img inside the block counts as 0-0-1. If two rules match in the same layer and have the same importance, a class selector beats it. Write :scope when you want to style the root itself; it counts as one class, 0-1-0.
At equal specificity, the scoped rule wins even when an unscoped rule comes later:
@scope (.card) { img { width: 48px; } }
img { width: 300px; }An image inside .card rendered at 48px with the rules in either order. The cascade spec checks scope proximity before order of appearance, and a rule without a scope root counts as infinite hops away.
When two scoped rules tie on origin, importance, layer and specificity, the root with fewer hops to the element wins.
Proximity only settles ties. Layers come first: with the scoped rule inside @layer components and a plain img { width: 300px } outside any layer, the image rendered at 300px. If your component styles live in layers, the order of your @layer list decides before @scope gets a say.