selector.parse() belongs to the built-in sass:selector module. It turns a selector string into Sass’s selector value format—a nested list you can inspect, loop, and pass to other selector helpers. This page covers that structure and five compiled examples.
01
Concept
String → selector list
02
Module
@use "sass:selector"
03
Returns
Selector (list)
04
Args
$selector
05
Structure
complex / compound
06
Practice
5 examples
Concept
What Is selector.parse()?
Official docs: returns $selector in the selector value format. Whenever sass:selector returns a selector, it is always a comma-separated list (the selector list) that contains space-separated lists (the complex selectors) that contain unquoted strings (the compound selectors).
For example, .main aside:hover, .sidebar p becomes two complex selectors: .main aside:hover and .sidebar p. The first complex selector has two compounds: .main and aside:hover.
Input may already be a string or another selector value—parse normalizes it.
Other selector functions often accept strings directly; parse shines for inspection and loops.
Interpolating the result usually prints a normal CSS selector string again.
💡
Beginner tip
Think of parse as “split the selector into Sass lists.” Commas separate complex selectors; spaces inside one complex selector separate compounds.
Foundation
📝 Syntax
styles.scss
@use "sass:selector";
// Recommended
selector.parse($selector)
// Legacy global name
selector-parse($selector)
Parameters
Parameter
Type
Required
Description
$selector
Selector / string
Yes
Selector to convert into the Sass selector value format.
Return value
Type
Result
Selector (list)
Comma list of complex selectors; each complex selector is a space-separated list of compound strings
Modules
📦 Loading sass:selector
styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:selector";
$parsed: selector.parse(".main aside:hover, .sidebar p");
// Optional — bring members into scope
@use "sass:selector" as *;
$parsed: parse(".card .title");
// Legacy global
$parsed: selector-parse(".card .title");
Details
🎨 Official Pattern & Structure
styles.scss
@use "sass:selector";
// Conceptual shape from the docs:
// ((unquote(".main") unquote("aside:hover")),
// (unquote(".sidebar") unquote("p")))
$parsed: selector.parse(".main aside:hover, .sidebar p");
Level
Separator
Example piece
Selector list
Comma
.main aside:hover | .sidebar p
Complex selector
Space
.main then aside:hover
Compound selector
—
Unquoted string like .main
Compare
⚖️ When Do You Need parse?
Goal
Need parse?
Call nest / append with a string
Usually no—strings are accepted
Count complex selectors / walk compounds
Yes—use list helpers on the parsed value
Loop each complex selector with @each
Yes
Normalize mixed inputs in a mixin API
Often yes
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Parsing happens at compile time.
Implementation
parse
Dart Sass
Yes — prefer selector.parse (module since 1.23.0)
LibSass
Legacy selector-parse may exist; no @use "sass:selector"
Ruby Sass
Legacy selector-parse may exist; no @use "sass:selector"
Prefer current Dart Sass so the module API matches the official docs.
The value is a Sass list. When printed into CSS, it looks like the original selector string again—the nested structure is for Sass code, not for browsers.
Example 2 — Walk Complex & Compound Parts
Use sass:list to measure both levels of the official sample.
Printing structure with inspect — inspect often looks like CSS text; use list.nth to see parts.
Old compilers without modules — use Dart Sass 1.23+ for @use "sass:selector".
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:selector" and selector.parse()
Parse when you need structure, loops, or normalization
Pair with sass:list for length / nth
Pass parsed values into other selector helpers when useful
Prefer Dart Sass 1.23+
❌ Don’t
Parse every string “just in case”
Assume browsers see the nested list format
Forget that a single complex selector is still a comma list of length 1
Confuse compounds with simple selectors (simple-selectors is a different helper)
Rely on LibSass for the module API
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about selector.parse()
Turn selector strings into Sass lists you can inspect, loop, and transform.
5
Core concepts
📝01
API
parse($selector)
Call
📦02
Module
sass:selector
@use
🔗03
Shape
list of lists
Format
📚04
Tools
list + @each
Inspect
✓05
Print
looks like CSS again
Emit
❓ 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.
Did you know?
Official Sass docs document the selector value format once for the whole sass:selector module—parse is the helper that turns a plain string into that shared nested-list shape.
selector.parse() converts a selector into Sass’s nested list format so you can inspect compounds, loop complex selectors, and feed structured values into other sass:selector helpers. Skip it when a plain string already works.