selector.append() belongs to the built-in sass:selector module. It glues selectors together without a descendant space—perfect for compound selectors and BEM-style suffixes. This page covers selector lists, vs selector.nest, and five compiled examples.
01
Concept
Glue selectors (no space)
02
Module
@use "sass:selector"
03
Returns
Selector value
04
Args
$selectors...
05
vs nest
Append ≠ descendant
06
Practice
5 examples
Concept
What Is selector.append()?
Official docs: combines $selectors without descendant combinators—that is, without whitespace between them. Use it when you want a.disabled or .accordion__copy, not a .disabled.
Takes one or more selector arguments ($selectors...).
If any argument is a selector list, each complex selector is combined separately.
Placeholder selectors are allowed; parent selectors (&) are not.
See also selector.nest() when you want nesting / descendant behavior.
💡
Beginner tip
Think of tape, not folders: append sticks class names onto the same element. nest puts one selector inside another (usually with a space).
Foundation
📝 Syntax
styles.scss
@use "sass:selector";
// Recommended
selector.append($selectors...)
// Legacy global name
selector-append($selectors...)
Parameters
Parameter
Type
Required
Description
$selectors...
Selectors
Yes (one or more)
Selectors to combine without descendant spaces. No parent selectors.
Return value
Type
Result
Selector
A combined selector (often usable inside #{…})
Modules
📦 Loading sass:selector
styles.scss
// Recommended — namespaced (Dart Sass 1.23+)
@use "sass:selector";
$sel: selector.append("a", ".disabled"); // a.disabled
// Optional — bring members into scope
@use "sass:selector" as *;
$sel: append("a", ".disabled");
// Legacy global
$sel: selector-append("a", ".disabled");
Details
🎨 Official Patterns
Call
Result
append("a", ".disabled")
a.disabled
append(".accordion", "__copy")
.accordion__copy
append(".accordion", "__copy, __image")
.accordion__copy, .accordion__image
The list case is the key detail: each side of the comma is appended separately to .accordion.
Compare
⚖️ append vs nest
Helper
Typical result
Use when
selector.append
.alert.warn (no space)
Same element / BEM suffix / compound class
selector.nest
.alert .warn (descendant) or .alert:hover with &
Nested stylesheet behavior / parent selectors
Support
🛠 Compatibility
This is about Sass compilers, not browsers. The combination runs at compile time.
Implementation
append
Dart Sass
Yes — prefer selector.append (module since 1.23.0)
LibSass
Legacy selector-append may exist; no @use "sass:selector"
Ruby Sass
Legacy selector-append 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";
Compound class
selector.append("a", ".disabled")
BEM element
selector.append(".block", "__el")
List of suffixes
selector.append(".block", "__a, __b")
Use as a selector
#{selector.append(".btn", ".primary")} { … }
Need a space / &
selector.nest(…) instead
Hands-On
Examples Gallery
Each example uses selector.append at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.
append keeps one compound selector. nest inserts a descendant combinator (space) between the two classes.
Applications
🚀 Real-World Use Cases
BEM tooling — build block__element and block--mod names from parts.
State helpers — append .is-active, :hover, or :focus-visible.
Component APIs — accept a base selector string and glue modifiers in mixins.
Selector lists — expand one prefix across several suffixes in one call.
Design-system codegen — loop tokens into consistent class names at compile time.
🧠 How Compilation Works
1
Pass selector pieces
Call selector.append(".btn", ".primary").
Source
2
Sass glues them
No descendant space; lists expand per complex selector.
Compile
3
Interpolate into rules
Use #{…} as the selector for a style block.
Emit
4
✓
CSS ships
Browsers only see finished selectors like .btn.primary.
Watch Out
⚠️ Common Pitfalls
Expecting a space — use selector.nest for descendants.
Parent selectors — & is not allowed in append arguments.
Forgetting interpolation — wrap results in #{…} to use them as rule selectors.
Accidental spaces in strings — " .mod" can produce odd compounds; keep pieces clean.
Old compilers without modules — use Dart Sass 1.23+ for @use "sass:selector".
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:selector" and selector.append()
Use it for compounds, BEM suffixes, and pseudos
Pass clean strings without leading spaces
Prefer list arguments for shared prefixes
Prefer Dart Sass 1.23+
❌ Don’t
Pass parent selectors (&)
Use append when you need a descendant combinator
Confuse it with string concatenation in every case—lists expand specially
Expect browsers to evaluate the call
Rely on LibSass for the module API
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about selector.append()
Glue selectors together without a descendant space—great for compounds and BEM.
5
Core concepts
📝01
API
append($selectors...)
Call
📦02
Module
sass:selector
@use
🔗03
Result
no-space selector
Output
📚04
Lists
combine separately
Detail
✓05
Alt
nest for spaces / &
Compare
❓ Frequently Asked Questions
selector.append($selectors...) combines selectors without descendant combinators—no whitespace between them. Example: append("a", ".disabled") becomes a.disabled.
append glues pieces together (a.disabled, .block__el). nest combines as if nested in the stylesheet, usually with a descendant space (ul li) unless you use &.
Official docs: if any argument is a selector list, each complex selector is combined separately. append(".accordion", "__copy, __image") becomes .accordion__copy, .accordion__image.
No. Official docs: arguments may contain placeholder selectors, but not parent selectors. Use selector.nest when you need &.
Yes. selector-append($selectors...) is the legacy global name. Prefer selector.append 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 highlight BEM-style suffixes like __copy because append is one of the few built-ins that builds those names without forcing a descendant combinator.
selector.append() combines selectors without descendant spaces—ideal for compounds, BEM suffixes, and pseudo-classes. Use lists to expand shared prefixes, avoid &, and reach for selector.nest when you need nesting behavior.