User Agents

Web browsers and everyday web tech, explained

Inspect Control CSS Scope Rules in Safari Web Inspector

· 6 min read · Browsers

In this article
  1. What CSS Scope Rules Are
  2. How Safari Web Inspector Shows Scope
  3. Inspecting Scope in the Sources Tab
  4. How to Choose Which Scope to Inspect
  5. Common Problems and Misconceptions
  6. Comparing Safari with Chrome and Firefox
  7. Performance and Debugging Tips
  8. Frequently Asked Questions

Yes, Safari's Web Inspector lets you inspect CSS scope rules directly: open the Styles sidebar, and any rule wrapped in @scope appears with its scope root and limit highlighted, plus a Scope badge you can click to jump to the containing element. This works in Safari 17 and later, where the inspector explicitly surfaces cascade layers, container queries, and scope boundaries alongside normal selectors.

What CSS Scope Rules Are

The @scope at-rule limits which elements a set of styles applies to, without relying on heavy class naming or !important hacks. A typical rule looks like:

@scope (.card) to (.card__footer) {
  .title { color: navy; }
}

Here, the .title rule only matches elements inside a .card and stops before the .card__footer boundary. The browser computes the scope root (the element matching .card) and the optional scope limit (the element matching .card__footer). The Web Inspector reflects this structure so you can see exactly which elements are in scope and why a style applies or not.

How Safari Web Inspector Shows Scope

When you select an element in the Elements tab, the Styles sidebar lists all matching rules. For a rule inside @scope, Safari adds a Scope badge next to the selector. Clicking that badge highlights the scope root in the page and shows a dashed outline around the scope’s boundary. The rule’s source link also includes the @scope line number, so you can jump straight to the CSS file.

In the Computed pane, you’ll see a Scope section that lists the root and limit elements for the selected node. If the selected element is not inside any scope, that section is empty. This is especially useful for debugging nested scopes, where an element might be inside multiple @scope blocks; the inspector shows the nearest one first.

Inspecting Scope in the Sources Tab

The Sources tab also respects scope. When you open a CSS file, the editor shows the @scope block as a collapsible section. You can click the scope root or limit to jump to that element in the page. The line numbers and syntax highlighting make it easy to see which rules belong to which scope, even in large stylesheets.

For a quick check, you can also use the Console to evaluate document.querySelectorAll('@scope') – but note that’s not standard CSS syntax; the real way is to inspect the rule via CSSStyleSheet.cssRules. In the console, you can run something like:

[...document.styleSheets].flatMap(s => [...s.cssRules]).filter(r => r.constructor.name === 'CSSScopeRule')

That returns all scope rules in the document, and each has .start and .end properties (the selectors for root and limit). This is a handy programmatic way to see what the inspector is showing visually.

How to Choose Which Scope to Inspect

If you have multiple nested scopes, the inspector shows the innermost one by default. To see outer scopes, click the scope badge and then use the breadcrumb trail that appears at the top of the Styles sidebar. That trail lists every scope that contains the selected element, from innermost to outermost. Click any entry to see that scope’s rule and its boundary.

For a scope with no limit (like @scope (.card)), the inspector shows only the root. If you want to see all elements inside a scope, you can click the scope badge and then select “Show all elements in scope” from the context menu – that highlights every element that matches the scope’s content selector.

Common Problems and Misconceptions

One common issue is that the scope badge doesn’t appear for rules that are overridden. If a rule is crossed out, the badge is still there but grayed out. That’s because the rule still exists, but a more specific or later rule wins. To see why, look at the rule’s specificity and source order in the Styles sidebar.

Another misconception: @scope does not create a new stacking context or a shadow DOM. It only affects selector matching. So you won’t see a “scope” entry in the Layers pane unless you also use @layer. The inspector treats scope and layers as separate features, though they can be combined.

Also, Safari’s Web Inspector does not show the scope’s “proximity” – the distance from the root to the element. That’s a CSS spec detail that isn’t exposed in the UI. If you need to know which element is the actual scope root for a given element, you can use the Computed pane’s Scope section, which lists the root element’s tag and class.

Comparing Safari with Chrome and Firefox

Chrome DevTools also supports @scope inspection since Chrome 118. It shows a similar badge, but the UI differs slightly: Chrome uses a “Scope” section in the Styles pane, and clicking the badge highlights the root with a purple outline. Firefox’s DevTools added scope support in Firefox 128, but it’s more basic – it shows the @scope rule in the Rules view, but without a dedicated badge or boundary highlighting. Safari’s approach is more visual, with the dashed outline and the breadcrumb trail for nested scopes.

If you’re used to Chrome, you’ll find Safari’s scope inspection intuitive, but the badge placement is on the right side of the rule, whereas Chrome puts it on the left. The ability to see all elements in a scope via a context menu is unique to Safari as of this writing.

Performance and Debugging Tips

When debugging scope-related issues, use the “Show all elements in scope” option to verify your selectors. If an element isn’t styled as expected, check whether it’s inside the scope root and before the limit. The inspector’s outline helps, but you can also use the Console to quickly test:

document.querySelector('.card').matches(':scope .title')

That returns true if the element matches the scope’s content selector. Also, remember that @scope does not affect the cascade’s specificity – it only adds a proximity factor. So a rule inside a scope can still be overridden by a higher-specificity rule outside the scope. The inspector shows the winning rule with a “cascade” tooltip that explains why it won.

For performance, scope rules are generally fast, but if you have thousands of scope roots, the browser has to check each one. The inspector can help you identify overly broad scopes by showing the number of matched elements when you hover over the scope badge.

Frequently Asked Questions

Why don’t I see the Scope badge in Safari Web Inspector?

Make sure you’re using Safari 17 or later. Also, the badge only appears for rules that are actually inside an @scope block. If you’re looking at a rule that uses a descendant selector like .card .title, that’s not a scope rule – it’s just a normal selector. The badge only shows for @scope at-rules.

Can I edit a scope rule in the inspector?

Yes. You can click on the rule text in the Styles sidebar and edit it just like any other rule. Changes apply live. You can also add or remove the @scope wrapper by editing the source in the Sources tab. The inspector will update the scope boundary immediately.

Does Safari’s Web Inspector show scope limits?

Yes. The dashed outline shows the limit element if one is defined. In the Computed pane, the Scope section lists both the root and the limit. If no limit is defined, it shows “None”.

How do I inspect a scope that is inside a shadow DOM?

Select the shadow root in the Elements tab, then switch to the Styles sidebar. Scope rules inside shadow trees appear with a “Shadow” badge. The scope root and limit are relative to the shadow tree, not the document. You can expand the shadow tree to see the elements.

What if my scope rule is not being applied?

Check that the scope root actually exists in the DOM and that the limit doesn’t cut off the element. Use the “Show all elements in scope” option to see the matched set. Also, verify that the rule isn’t overridden by a higher-specificity rule – the inspector will show the winning rule with a strikethrough on the losing one.

Is there a keyboard shortcut to highlight scope?

Yes. When you have a rule selected in the Styles sidebar, press Option+Click on the Scope badge to toggle the outline. This is faster than using the context menu.