Sub topic 12
Browser support and fallback strategy
This chapter covers how to ship @scope to real users. It explains what happens in a browser that doesn't understand the rule, how to detect support, and how to write CSS that works either way.
It assumes you have read the earlier chapters. You should know scope roots, scope limits, the :scope pseudo-class, the cascade (specificity, then scope proximity, then order of appearance), and basic CSS nesting. You should also know @layer at a basic level.
Where support stands
@scope shipped in Chromium browsers (Chrome and Edge 118) in October 2023. Safari followed in version 17.4 in March 2024. Firefox was the last major engine to ship it, with version 146 in late 2025 according to MDN's compatibility data at the time of writing.
| Engine | First version with `@scope` |
|---|---|
| Chrome, Edge (Chromium) | 118 |
| Safari | 17.4 |
| Firefox | 146 |
Treat this table as a snapshot. Before you decide on a strategy, check the current numbers on MDN or Can I Use and compare them with your own analytics. What matters is the share of your visitors on browsers older than these versions. That share depends on your audience. A public site with many long-lived mobile devices and a corporate intranet have very different answers.
Two things make the picture more complicated than "supported or not":
- Browsers that updated recently support it. Browsers that can't update, such as old iPads stuck on an old Safari, never will.
- Features inside
@scopearrived together, but features around it did not. For example, relative selectors in nesting and@supports at-rule()have their own support histories.
What an unsupporting browser does
CSS has a defined error-recovery rule for unknown at-rules. When a parser meets an at-rule it doesn't recognize, it skips the whole thing, including the block in braces. It then continues with the next rule.
The following CSS shows what that means in practice.
.card {
padding: 1rem;
}
@scope (.card) {
a {
color: rebeccapurple;
}
img {
width: 100%;
}
}
footer {
color: gray;
}In an old browser, .card { padding: 1rem; } and footer { color: gray; } apply. Everything inside @scope is dropped. The links keep the default color and the images keep their natural size. Nothing throws an error and nothing shows in the console. The page just looks unstyled in the parts that depended on the scope.
This has a direct design consequence. Whatever you put inside @scope must be either:
- an enhancement that you can live without, or
- something with an equivalent fallback elsewhere in the stylesheet.
You can't write @scope as the only styling for critical layout and assume the old browser will "mostly" work. It will lose all of it.
Deciding whether you need a fallback
Work through the questions below before you write any fallback code.
Most real projects land in one of three places:
- Use it directly. If your supported-browser share is high enough for your project's policy, write
@scopeand stop. Internal tools and sites that already require recent browsers often qualify. - Use it as an enhancement. The page is fully usable and readable without the scoped rules. Only polish is lost.
- Write a fallback. The scoped rules carry real layout or readability, so an equivalent has to exist for older browsers.
Detecting support
You have three ways to detect support. They differ a lot in reliability.
Detection in CSS with `@supports`
The CSS @supports rule can test for an at-rule with the at-rule() function, as in @supports at-rule(@scope). This is the natural fit, but the at-rule() function itself is new and not universally implemented. In a browser that doesn't understand at-rule(), the test is false even when the browser does support @scope. A fallback gated on that test would then run in the wrong browsers. Don't build a production strategy on it yet. Check its current support first.
Detection in JavaScript
The CSS Object Model exposes a CSSScopeRule interface in browsers that support the rule. You can test for it.
const supportsScope = typeof CSSScopeRule !== "undefined";
document.documentElement.classList.toggle("no-scope", !supportsScope);This puts a no-scope class on the <html> element when support is missing. Your fallback rules can then start with .no-scope. The cost is that the check runs after the script loads, so the first paint can flash unstyled content. Put the script inline in the <head> to keep the flash short, and only if you really need this approach.
Detection by structure
The most robust option needs no detection at all. You write CSS so that the fallback and the scoped version are both present and agree. A supporting browser applies both, and an old browser applies only the fallback. The next section shows how to do this safely.
Writing a layered fallback
The simplest fallback is a plain selector that targets the same elements as the scope.
.card a {
color: rebeccapurple;
}
@scope (.card) {
a {
color: rebeccapurple;
}
}In a supporting browser both rules apply to the same links. They have the same declarations, so which one wins doesn't matter. The trouble starts when you later change one and forget the other, or when other rules interact with them.
The specificity gap is the first problem. Recall from the specificity chapter that the scope root adds nothing to the specificity of selectors inside @scope. The scoped a has specificity (0,0,1). The fallback .card a has (0,1,1). If some other rule sits between those two, such as a:hover at (0,1,1), the fallback and the scoped rule behave differently. A supporting browser would then give different results from an old one.
You can remove the gap by writing the fallback with :where(), which always contributes zero specificity.
:where(.card) a {
color: rebeccapurple;
}Now the fallback has specificity (0,0,1), the same as the scoped rule. Both versions of the rule take part in the cascade at the same weight.
Cascade layers make the intent explicit and control which version wins in a supporting browser.
@layer fallback, scoped;
@layer fallback {
:where(.card) a {
color: rebeccapurple;
}
:where(.card) img {
width: 100%;
}
}
@layer scoped {
@scope (.card) {
a {
color: rebeccapurple;
}
img {
width: 100%;
}
}
}The first line fixes the layer order, and the scoped layer comes last, so it beats fallback in the cascade whatever the specificity or order of the rules. Layers have been supported far longer than @scope (Chrome 99, Firefox 97, Safari 15.4), so an old browser that lacks @scope still understands this file. It reads the fallback layer and skips the @scope block inside the scoped layer.
This design keeps the two versions in separate places. When you stop supporting old browsers, you delete the fallback layer and the layer order line. The scoped code needs no edits.
Approximating a donut scope
A scope limit is the hardest feature to imitate. Recall the earlier rule:
@scope (.card) to (.card-content) {
img {
border-radius: 50%;
}
}An approximation that old browsers understand uses :not() with a complex selector:
:where(.card) img:not(:where(.card-content) img) {
border-radius: 50%;
}This selects images inside .card that are not inside .card-content. The :not() pseudo-class accepts a complex selector in all major browsers released since 2021. Wrapping the root and the limit in :where() keeps the specificity low. Note that :not() takes the specificity of its most specific argument. Here that argument is :where(.card-content) img, which counts as (0,0,1). The whole rule comes to (0,0,2), which is one type selector higher than the scoped version. If the two versions must tie exactly, keep that difference in mind when you pick the layer order.
The approximation has limits:
- It can't reproduce scope proximity. An old browser decides by specificity and order only, so nested themes such as
.lightinside.darkmay resolve differently. - With nested cards,
.card .card-content .card imgis inside a content area but also inside an inner card. Real@scopetreats the inner card as a new scope root. The:not()version can exclude it.
For these cases, check the result in an old browser instead of trusting the equivalence.
Inline scope with no prelude
An inline @scope inside a <style> element has no selector, so there's nothing to approximate with :where(). In an old browser, the whole <style> block is dropped.
<section class="promo">
<style>
@scope {
h2 { color: crimson; }
}
</style>
<h2>Sale ends soon</h2>
</section>The inline form is the least portable form. The fallback is to write the same rule with a real class, such as .promo h2, in your normal stylesheet. If you need old-browser support, prefer the explicit @scope (.promo) form in a stylesheet, which you can pair with a layered fallback.
Build tools
Some build tools can rewrite @scope into ordinary selectors. This resembles what CSS Modules and BEM tooling do already. It has two costs:
- It brings back the build step that
@scopelets you avoid. - Compiled selectors can't mimic scope proximity or the exact scope limit behavior in every case.
If you already run a CSS build step for other reasons, a transform may be cheaper than hand-written fallbacks. Check what the tool does with proximity and limits before you rely on it.
A short checklist
- Look up your real browser share with no
@scopesupport. - Decide whether the scoped rules are enhancements or required.
- For required rules, write a fallback layer using
:where()on the root. - Declare the layer order first, with the scoped layer last.
- Approximate scope limits with
:not()and test nested cases. - Test in an old browser or with the
@scopeblock removed. - Plan the removal. Put a comment on the fallback layer that says when to delete it.
Exercise
A stylesheet has @scope (.nav) { a { color: navy; } } and no other rule for links in .nav. A visitor uses a browser without @scope support. What do they see for those links, and how would you add a fallback that has the same specificity as the scoped rule?
Show answer
The browser skips the whole @scope block as an unknown at-rule, so the links keep their default color and no error is shown. A fallback is :where(.nav) a { color: navy; }. The :where() makes the root add no specificity, so the rule has specificity (0,0,1), the same as the a inside the scope. For clearer control, put it in a fallback layer, declare @layer fallback, scoped; first, and put the @scope rule in the scoped layer, so that the scoped version wins in supporting browsers.
Exercise
Why is @supports at-rule(@scope) risky as the only gate for a fallback today?
Show answer
The at-rule() function in @supports is newer and less widely implemented than @scope. A browser that supports @scope but not at-rule() evaluates the test as false, so a fallback gated on it would run in a browser that doesn't need it. A layered fallback without detection, or a check for CSSScopeRule in JavaScript, avoids that problem.