selector.parse($selector) returns $selector in the Sass selector value format: a comma-separated list (selector list) of space-separated lists (complex selectors) of unquoted strings (compound selectors). Load with @use "sass:selector".
Official sample idea.
parse(".main aside:hover, .sidebar p") becomes two complex selectors: .main aside:hover and .sidebar p.
Why parse?
Most selector helpers already accept strings. Use parse when you need to walk structure with list.length / list.nth, loop complexes, or normalize input.
Browsers see a string again.
Interpolating a parsed selector usually prints a normal selector. The nested list is for Sass code—see also meta.inspect().
Syntax
Syntax
SCSS
@use "sass:selector";
selector.parse($selector) //=> selector (list)
$parsed: selector.parse(".main aside:hover, .sidebar p");
// two complex selectors:
// (.main aside:hover)
// (.sidebar p)
// Feed into other helpers:
selector.nest($parsed, "&:hover");
selector.append(selector.parse(".btn"), ".primary");
// Global alias (legacy): selector-parse($selector)
// Prefer selector.parse after @use "sass:selector"
Pattern: pass a selector string → get a nested list → inspect with sass:list or pass to other selector helpers.
Reference
Selector Value Format
Three nested levels, matching the module docs:
Level
Meaning
Example piece
Outer list (comma)
Selector list
.main aside:hover, .sidebar p
Inner list (space)
Complex selector
.main aside:hover
Unquoted string
Compound selector
.main, aside:hover
Official shape.
Returned selectors are always this nested list form—even when you started from a plain string.
Returns a nested list — comma complexes, space compounds.
Walk with sass:list when you need counts or parts.
Feeds other helpers like nest and append.
Prefer @use "sass:selector" (Dart Sass 1.23+).
One line: to turn a selector string into Sass’s nested list format, use selector.parse($selector).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:selector"
2. Pass a selector string to parse
3. Use list.length / list.nth to walk levels
4. Feed the result into nest, append, etc.
5. Remember CSS output looks like a normal selector
Frequently Asked Questions
selector.parse($selector) returns $selector in the Sass selector value format: a comma-separated list of complex selectors, each a space-separated list of compound selectors (unquoted strings).
Most selector helpers accept strings. parse is useful when you want to inspect structure with list.length / list.nth, loop complex selectors, or normalize input before further selector work.
parse(".main aside:hover, .sidebar p") becomes a list of two complex selectors: (.main aside:hover) and (.sidebar p). Each complex selector is itself a list of compounds.
Yes. selector-parse($selector) is the legacy global name. Prefer selector.parse after @use "sass:selector".
Yes. Interpolating a parsed selector with #{$parsed} (or meta.inspect) usually prints a normal selector string again.
Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:selector with @use; they may still offer the legacy global name.