1.3 · Selectors & structure

Styles with edges: @scope

Limit styles to a component, and stop them before nested content.

@scope (.card) applies its rules only inside .card. Adding to (.content) sets a lower boundary, so the styles stop before they reach nested content. This is often called donut scope. You get component-style isolation without naming conventions or shadow DOM.

Scope also adds a new step to the cascade: proximity. When two scoped rules have equal specificity, the one whose scope root is closer in the DOM wins. That makes nested light and dark themes behave the way you expect.

Before
/* Long names so nothing leaks */
.card__title { … }
.card__text { … }

/* And hope nobody nests a card
   title inside .card .content */
Now
@scope (.card) to (.content) {
  :scope { border: 2px solid; }
  .title { text-transform: uppercase; }
  p { font-style: italic; }
}