selector.is-superselector() belongs to the built-in sass:selector module. It asks: does selector A match every element that selector B matches? This page covers $super vs $sub, official link examples, branching helpers, and five compiled examples.
01
Concept
Does A cover B?
02
Module
@use "sass:selector"
03
Returns
true / false
04
Args
$super, $sub
05
Limits
No & parents
06
Practice
5 examples
Concept
What Is selector.is-superselector()?
Official docs: returns whether the selector $super matches all the elements that the selector $sub matches. It still returns true when $super matches more elements than $sub.
$super is the broader / covering selector; $sub is the narrower one.
Equal selectors return true (a selector covers itself).
Arguments may be strings or selector values; placeholders are allowed.
Parent selectors (&) are not allowed in either argument.
💡
Beginner tip
Think of umbrellas: "a" covers every "a.disabled" link. But "a.disabled" does not cover every "a"—some links are not disabled.
Foundation
📝 Syntax
styles.scss
@use "sass:selector";
// Recommended
selector.is-superselector($super, $sub)
// Legacy global name
is-superselector($super, $sub)
Parameters
Parameter
Type
Required
Description
$super
Selector
Yes
Candidate covering selector (string or selector value). No parent selectors.
$sub
Selector
Yes
Selector whose matched elements must all be matched by $super.
Return value
Type
Result
Boolean
true if $super covers $sub; otherwise false
Modules
📦 Loading sass:selector
styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:selector";
$ok: selector.is-superselector("a", "a.disabled");
// Optional — bring members into scope
@use "sass:selector" as *;
$ok: is-superselector("a", "a.disabled");
// Legacy global
$ok: is-superselector("a", "a.disabled");
Details
⚖️ Reading $super vs $sub
Official examples make the direction clear:
Call
Result
Why
is-superselector("a", "a.disabled")
true
Every disabled link is still an a
is-superselector("a.disabled", "a")
false
Not every a is disabled
is-superselector("a", "sidebar a")
true
Every sidebar link is still an a
is-superselector("sidebar a", "a")
false
Not every a lives in a sidebar
is-superselector("a", "a")
true
A selector covers itself
Compare
📋 Related Selector Helpers
Helper
Purpose
selector.is-superselector
Does one selector cover another?
selector.unify
Build a selector that matches both (or null)
selector.append
Combine without a descendant combinator
selector.nest
Combine as if nested in the stylesheet
selector.parse
Normalize a string into a selector value
Support
🛠 Compatibility
This is about Sass compilers, not browsers. The check runs at compile time.
Implementation
is-superselector
Dart Sass
Yes — prefer selector.is-superselector (module since 1.23.0)
LibSass
Legacy global may exist; no @use "sass:selector"
Ruby Sass
Legacy global may exist; no @use "sass:selector"
Prefer current Dart Sass so the module API matches the official docs.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import selector
@use "sass:selector";
Does A cover B?
selector.is-superselector($a, $b)
Class covers modifier
selector.is-superselector(".btn", ".btn.primary")
Branch in a mixin
@if selector.is-superselector($base, $spec) { … }
Legacy global
is-superselector($super, $sub)
Hands-On
Examples Gallery
Each example uses selector.is-superselector at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.
📚 Getting Started
Official link examples, then familiar class modifiers.
Example 1 — Official Link Checks
Reproduce the Sass docs samples as CSS custom properties.
.nav a covers its active state, but not footer links. The active selector is too narrow to cover every nav link.
Applications
🚀 Real-World Use Cases
API validation — ensure a “base” selector really covers a more specific one.
Mixin guards — skip redundant nesting when a selector already covers another.
Design-system checks — confirm BEM modifiers stay under their block class.
Selector tooling — build compile-time reports for theme or layout packs.
Safer abstractions — fail early when callers invert broad and narrow selectors.
🧠 How Compilation Works
1
Pass two selectors
Call selector.is-superselector($super, $sub).
Source
2
Sass compares match sets
Checks whether every element matched by $sub is also matched by $super.
Compile
3
Boolean drives @if
Your mixin or function keeps or skips optional selector paths.
Branch
4
✓
CSS ships
Browsers never see is-superselector—only finished rules.
Watch Out
⚠️ Common Pitfalls
Swapping arguments — broader selector must be $super, not $sub.
Parent selectors — & is not allowed in either argument.
Thinking “contains string” — this is about matched elements, not substring checks.
Expecting runtime — everything resolves when Sass compiles.
Old compilers without modules — use Dart Sass 1.23+ for @use "sass:selector".
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:selector" and selector.is-superselector()
Put the broader selector first
Pass plain selector strings without &
Use it to validate mixin APIs
Prefer Dart Sass 1.23+
❌ Don’t
Pass parent selectors in either argument
Assume string containment equals coverage
Forget equal selectors return true
Expect browsers to evaluate the check
Rely on LibSass for the module API
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about selector.is-superselector()
Ask whether one selector covers every element matched by another.
5
Core concepts
📝01
API
is-superselector($super, $sub)
Call
📦02
Module
sass:selector
@use
✅03
Returns
boolean
Result
⚖️04
Order
broader first
Rule
✓05
Limit
no & parents
Watch
❓ Frequently Asked Questions
selector.is-superselector($super, $sub) returns true if $super matches every element that $sub matches. It can still be true when $super matches extra elements beyond $sub.
Pass the broader (covering) selector as $super and the narrower one as $sub. Example: is-superselector("a", "a.disabled") is true because every a.disabled is also an a.
No. Official docs: $super and $sub may contain placeholder selectors, but not parent selectors.
Yes. is-superselector("a.disabled", "a") is false—a.disabled does not match every a.
Yes. is-superselector($super, $sub) is the legacy global name. Prefer selector.is-superselector after @use "sass:selector".
Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:selector with @use; they may still offer the legacy global name.
Did you know?
Official Sass docs still return true when $super matches extra elements beyond $sub. Coverage means “at least everything in the sub-selector,” not “exactly the same set.”
selector.is-superselector() returns whether one selector covers every element matched by another. Pass the broader selector first, avoid parent selectors, and use the boolean to build safer selector APIs on Dart Sass 1.23+.