Sass selector.is-superselector() Function

Intermediate
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:selector · Dart Sass 1.23+

What You’ll Learn

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

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.

📝 Syntax

styles.scss
@use "sass:selector";

// Recommended
selector.is-superselector($super, $sub)

// Legacy global name
is-superselector($super, $sub)

Parameters

ParameterTypeRequiredDescription
$superSelectorYesCandidate covering selector (string or selector value). No parent selectors.
$subSelectorYesSelector whose matched elements must all be matched by $super.

Return value

TypeResult
Booleantrue if $super covers $sub; otherwise false

📦 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");

⚖️ Reading $super vs $sub

Official examples make the direction clear:

CallResultWhy
is-superselector("a", "a.disabled")trueEvery disabled link is still an a
is-superselector("a.disabled", "a")falseNot every a is disabled
is-superselector("a", "sidebar a")trueEvery sidebar link is still an a
is-superselector("sidebar a", "a")falseNot every a lives in a sidebar
is-superselector("a", "a")trueA selector covers itself

📋 Related Selector Helpers

HelperPurpose
selector.is-superselectorDoes one selector cover another?
selector.unifyBuild a selector that matches both (or null)
selector.appendCombine without a descendant combinator
selector.nestCombine as if nested in the stylesheet
selector.parseNormalize a string into a selector value

🛠 Compatibility

This is about Sass compilers, not browsers. The check runs at compile time.

Implementationis-superselector
Dart SassYes — prefer selector.is-superselector (module since 1.23.0)
LibSassLegacy global may exist; no @use "sass:selector"
Ruby SassLegacy global may exist; no @use "sass:selector"

Prefer current Dart Sass so the module API matches the official docs.

⚡ Quick Reference

GoalCode
Import selector@use "sass:selector";
Does A cover B?selector.is-superselector($a, $b)
Class covers modifierselector.is-superselector(".btn", ".btn.primary")
Branch in a mixin@if selector.is-superselector($base, $spec) { … }
Legacy globalis-superselector($super, $sub)

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.

styles.scss
@use "sass:selector";

.probe {
  --a-over-disabled: #{selector.is-superselector("a", "a.disabled")};
  --disabled-over-a: #{selector.is-superselector("a.disabled", "a")};
  --a-over-sidebar: #{selector.is-superselector("a", "sidebar a")};
  --sidebar-over-a: #{selector.is-superselector("sidebar a", "a")};
  --same: #{selector.is-superselector("a", "a")};
}

How It Works

Broader selectors in the first argument return true. Swapping the arguments flips the result when the coverage is one-way.

Example 2 — Class vs Modifier

A base class covers a more specific compound selector.

styles.scss
@use "sass:selector";

.probe {
  --btn-over-primary: #{selector.is-superselector(".btn", ".btn.primary")};
  --primary-over-btn: #{selector.is-superselector(".btn.primary", ".btn")};
  --equal: #{selector.is-superselector(".btn", ".btn")};
}

How It Works

Every .btn.primary is a .btn, but not every .btn is primary.

📈 Practical Patterns

Branching mixins, descendant checks, and nav coverage reports.

Example 3 — Branch on Coverage

Emit different rules depending on whether the base covers the specific selector.

styles.scss
@use "sass:selector";

@mixin maybe-base($base, $specific) {
  @if selector.is-superselector($base, $specific) {
    #{$base} {
      --covers: true;
      color: teal;
    }
  } @else {
    #{$base} {
      --covers: false;
      color: tomato;
    }
  }
}

@include maybe-base("a", "a.disabled");
@include maybe-base("a.disabled", "a");

How It Works

The first include treats a as covering a.disabled. The second cannot cover every a, so it marks a.disabled as not covering.

Example 4 — Element vs Descendant

An element selector covers a descendant form of itself; the reverse does not.

styles.scss
@use "sass:selector";

.flags {
  --descendant: #{selector.is-superselector("h1", "main h1")};
  --too-narrow: #{selector.is-superselector("main h1", "h1")};
  --same: #{selector.is-superselector(".card", ".card")};
}

How It Works

Every main h1 is an h1, but not every h1 is inside main.

Example 5 — Nav Coverage Helper

Wrap the check in a small function for reusable reports.

styles.scss
@use "sass:selector";

@function covers($super, $sub) {
  @return selector.is-superselector($super, $sub);
}

$base: ".nav a";
$item: ".nav a.active";
$other: "footer a";

.report {
  --nav-covers-active: #{covers($base, $item)};
  --nav-covers-footer: #{covers($base, $other)};
  --active-covers-nav: #{covers($item, $base)};
}

How It Works

.nav a covers its active state, but not footer links. The active selector is too narrow to cover every nav link.

🚀 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.

⚠️ 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".

💡 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

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
📦 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.”

Conclusion

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+.

Continue with selector.nest() or the Sass introduction.

Next: nest selectors

Learn selector.nest() to combine selectors like nested SCSS.

selector.nest() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful