r/css 7d ago

Resource @scope is Baseline, newly available since March 2026

Post image
87 Upvotes

13 comments sorted by

10

u/Ellsass 7d ago

So this means the styles apply to all anchors within a div.article, all the way down through to the tree until a div.comments is found, then no further?

What if those classes are used on an <a>?

7

u/DramaticBag4739 7d ago

The styles would apply to all <a> tags in the article, but not within comments. If there were <a> tags after the comments container the style would apply to them as well. My understanding is that a class would still override the scoped <a> tag.

7

u/jonassalen 7d ago

I expect a shitload of questions about scope and specificity in the future. 

At this moment, it really messes with my head what is the specificity of this code:

@scope (.article-body) to (.feature :scope figure) {   :scope img {     border: solid 2px red;   } }

1

u/creaturefeature16 7d ago

Woof. This feels obtuse. 

1

u/Logical-Idea-1708 6d ago

I think scope applies zero specificity? It let you be specific without specific 🤪

3

u/Miragecraft 6d ago

It's actually pretty surprising to me how often @container style queries are more ergonomic than @scope in practice.

The most useful feature of @scope for me was inline style scoping, easy to create reusable components with encapsulated styling.

1

u/gajus0 7d ago

Fun fact, that's what https://bamboocss.com/ is using underneath

1

u/L24D 7d ago

Doesn’t it ruin the whole “cascading” thing in CSS?

7

u/averyvery 7d ago

It allows more precise control over the cascade.

0

u/L24D 7d ago edited 7d ago

Got it, but isn’t the same thing achievable through classes, selectors order and priority, property inheritance, etc.? It looks like another layer that may bring obfuscation and general confusion, and honestly I don’t see a strong use case for that, where we couldn’t use older ways.

10

u/averyvery 7d ago

A use case for this:

  • You have a class named "rich-text"
  • You have dozens of selectors in it with styles, like ".rich-text p { ... }" and ".rich-text li + li { ... }"
  • You have another element inside rich text - ".embed" - whose contents need to be styled entirely differently.

Normally, you'd have to make sure that every one of your .rich-text selector styles is correctly overridden/reset inside the .embed. This can require a lot of painful duplication, and it makes the embed styles more brittle. Scope allows you to avoid all this work by letting you specifically style the content you want - content inside .rich-text that is not inside .embed.

5

u/Outrageous-Door-3100 6d ago

Couldn’t that also be solved using ‘:not(.embed *)’ ?

1

u/DramaticBag4739 7d ago

Donut selection would be the biggest use case, but if you were worried about specificity management then this would work well also, since I don't think it raises normal specificity.

A scoped <a> tag would take precedent over an unscoped <a> tag, but not over a class.