Sass selector.simple-selectors() Function

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

What You’ll Learn

selector.simple-selectors() belongs to the built-in sass:selector module. It splits one compound selector into its simple pieces—tags, classes, IDs, and pseudos. This page covers the compound-only rule, list helpers, and five compiled examples.

01

Concept

Compound → simples

02

Module

@use "sass:selector"

03

Returns

Comma list

04

Args

$selector

05

Limit

No spaces / commas

06

Practice

5 examples

What Is selector.simple-selectors()?

Official docs: returns a list of simple selectors in $selector. The argument must be a single string that contains a compound selector—no combinators (including spaces) and no commas.

  • The returned list is comma-separated.
  • Each simple selector is an unquoted string (a, .disabled, :after).
  • Use sass:list / @each to walk the parts.
  • For full selector lists with spaces or commas, use selector.parse() instead.
💡
Beginner tip

A compound selector targets one element with several conditions stuck together: a.disabled means “an a that also has class disabled.” This helper pulls those conditions apart.

📝 Syntax

styles.scss
@use "sass:selector";

// Recommended
selector.simple-selectors($selector)

// Legacy global name
simple-selectors($selector)

Parameters

ParameterTypeRequiredDescription
$selectorString (compound selector)YesOne compound selector—no spaces, no commas, no other combinators.

Return value

TypeResult
ListComma-separated list of unquoted simple-selector strings

📦 Loading sass:selector

styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:selector";
$parts: selector.simple-selectors("a.disabled"); // a, .disabled

// Optional — bring members into scope
@use "sass:selector" as *;
$parts: simple-selectors("main.blog:after");

// Legacy global
$parts: simple-selectors("a.disabled");

🎨 Official Patterns

CallResult
simple-selectors("a.disabled")a, .disabled
simple-selectors("main.blog:after")main, .blog, :after

Tags, classes, and pseudo-elements/classes all count as separate simple selectors when they sit in the same compound.

⚖️ simple-selectors vs parse

HelperInputWhat you get
selector.simple-selectorsOne compound (a.disabled)List of simple pieces
selector.parseFull selector list (.a .b, .c)Nested complex/compound lists

🛠 Compatibility

This is about Sass compilers, not browsers. Splitting happens at compile time.

Implementationsimple-selectors
Dart SassYes — prefer selector.simple-selectors (module since 1.23.0)
LibSassLegacy simple-selectors may exist; no @use "sass:selector"
Ruby SassLegacy simple-selectors 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";
Split a compoundselector.simple-selectors("a.disabled")
Count partslist.length(selector.simple-selectors($sel))
First / last partlist.nth($parts, 1) / list.nth($parts, -1)
Loop parts@each $simple in selector.simple-selectors($sel)
Need spaces / commasselector.parse(…) instead

Examples Gallery

Each example uses selector.simple-selectors at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.

📚 Getting Started

Official docs samples, then list access.

Example 1 — Official Simple-Selectors Samples

Split compounds and count the pieces.

styles.scss
@use "sass:list";
@use "sass:meta";
@use "sass:selector";

$parts: selector.simple-selectors("a.disabled");
$parts2: selector.simple-selectors("main.blog:after");

.probe {
  --disabled: #{meta.inspect($parts)};
  --blog: #{meta.inspect($parts2)};
  --len: #{list.length($parts2)};
}

How It Works

meta.inspect shows the comma list. Length matches how many simple pieces sit in the compound.

Example 2 — Read Each Part with list.nth

Pull tag, classes, and a pseudo out of one compound.

styles.scss
@use "sass:list";
@use "sass:meta";
@use "sass:selector";

$parts: selector.simple-selectors("button.btn.primary:hover");

.probe {
  --1: #{meta.inspect(list.nth($parts, 1))};
  --2: #{meta.inspect(list.nth($parts, 2))};
  --3: #{meta.inspect(list.nth($parts, 3))};
  --4: #{meta.inspect(list.nth($parts, 4))};
}

How It Works

Order follows the compound left to right: type selector, then classes, then the pseudo.

📈 Practical Patterns

Loops, rebuilds, and pseudo checks.

Example 3 — Loop with @each

Emit one rule per simple selector.

styles.scss
@use "sass:selector";

@mixin each-simple($compound) {
  @each $simple in selector.simple-selectors($compound) {
    .part {
      content: "#{$simple}";
    }
  }
}

@include each-simple("a.disabled");

How It Works

The comma list from simple-selectors is directly usable in @each.

Example 4 — Count, Peek, and Rebuild

Inspect ends of the list, then glue the first two parts with append.

styles.scss
@use "sass:list";
@use "sass:meta";
@use "sass:selector";

$parts: selector.simple-selectors(".card.featured.is-active");

.probe {
  --count: #{list.length($parts)};
  --first: #{meta.inspect(list.nth($parts, 1))};
  --last: #{meta.inspect(list.nth($parts, -1))};
  --rebuilt: #{selector.append(list.nth($parts, 1), list.nth($parts, 2))};
}

How It Works

Negative indices work with list.nth. selector.append can put simple pieces back together without a space.

Example 5 — Detect a Pseudo-Class

Scan the simple list for a specific piece.

styles.scss
@use "sass:selector";

@function has-pseudo($compound, $pseudo) {
  @each $simple in selector.simple-selectors($compound) {
    @if $simple == $pseudo {
      @return true;
    }
  }
  @return false;
}

.check {
  --hover: #{has-pseudo("a.link:hover", ":hover")};
  --focus: #{has-pseudo("a.link:hover", ":focus")};
}

How It Works

Because each simple selector is a string in the list, equality checks are straightforward for mixin/function guards.

🚀 Real-World Use Cases

  • Validation — require a type selector or forbid certain pseudos.
  • Design-system APIs — accept a compound string and branch on its parts.
  • Debugging — print each simple piece with meta.inspect.
  • Rebuild helpers — drop or swap one simple selector, then append again.
  • Teaching CSS — show beginners what lives inside a compound selector.

🧠 How Compilation Works

1

Pass one compound

Call selector.simple-selectors("a.disabled").

Source
2

Sass splits simples

Builds a comma list of unquoted strings.

Compile
3

Inspect or loop

Use list, @each, or rebuild with append.

Use
4

CSS ships

Browsers never see the list—only the CSS you emit from it.

⚠️ Common Pitfalls

  • Passing descendants"ul li" has a space; use parse, not simple-selectors.
  • Passing selector lists — commas are not allowed in the input.
  • Expecting nested lists — you get a flat comma list of strings.
  • Confusing with parse — parse handles full selector structure; this helper is compound-only.
  • Old compilers without modules — use Dart Sass 1.23+ for @use "sass:selector".

💡 Best Practices

✅ Do

  • Use @use "sass:selector" and selector.simple-selectors()
  • Pass clean compound strings only
  • Pair with sass:list and @each
  • Use parse when you need spaces or commas
  • Prefer Dart Sass 1.23+

❌ Don’t

  • Pass combinators or selector lists
  • Assume the result is a nested selector-value list like parse
  • Forget quotes when comparing string pieces in @if
  • Expect browsers to evaluate the call
  • Rely on LibSass for the module API

Key Takeaways

Knowledge Unlocked

Five things to remember about selector.simple-selectors()

Split one compound selector into a comma list of simple string pieces.

5
Core concepts
📦 02

Module

sass:selector

@use
🔗 03

Input

compound only

Rule
📚 04

Output

comma list

List
05

Alt

parse for lists

Compare

❓ Frequently Asked Questions

selector.simple-selectors($selector) returns a comma-separated list of the simple selectors inside a compound selector. Example: simple-selectors("a.disabled") becomes a, .disabled.
Official docs: $selector must be a single string that contains a compound selector. It may not contain combinators (including spaces) or commas. So "a.disabled" is OK; "ul li" or "a, button" is not.
The returned list is comma-separated, and the simple selectors are unquoted strings. Example: simple-selectors("main.blog:after") becomes main, .blog, :after.
Yes. simple-selectors($selector) is also available as a legacy global name. Prefer selector.simple-selectors after @use "sass:selector".
parse handles full selector lists with commas and spaces (complex selectors). simple-selectors only splits one compound selector into its simple pieces.
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 emphasize that the input must be a compound selector string—so this helper is intentionally narrower than selector.parse, which understands full selector lists.

Conclusion

selector.simple-selectors() splits one compound selector into a comma list of simple string pieces. Keep inputs free of spaces and commas, walk the list with sass:list or @each, and use parse for fuller selector structures.

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

Next: unify selectors

Learn selector.unify() to build the overlap of two selectors.

selector.unify() →

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