Home Sass List list.join() Sass list.join() Definition
Definition and Usage list.join($list1, $list2, $separator: auto, $bracketed: auto) returns a new list with every element of $list1 followed by every element of $list2 — flattened into one list. Load it with @use "sass:list" on Dart Sass 1.23+ . Global alias: join().
Prefer append for one value. Official docs: because single values count as one-item lists, join can add a value — but if that value is a list it will be concatenated. Use list.append() to add one item; use join to combine two lists.
Official samples. list.join(10px 20px, 30px 40px) → 10px 20px 30px 40px. list.join((blue, red), (#abc, #def)) → blue, red, #abc, #def. list.join(10px, 20px, $bracketed: true) → [10px 20px].
Syntax
Syntax @use "sass:list";
list.join(10px 20px, 30px 40px); // 10px 20px 30px 40px
list.join((blue, red), (#abc, #def)); // blue, red, #abc, #def
list.join(10px, 20px); // 10px 20px
list.join(10px, 20px, $separator: comma); // 10px, 20px
list.join((blue, red), (#abc, #def), $separator: space); // blue red #abc #def
list.join([10px], 20px); // [10px 20px]
list.join(10px, 20px, $bracketed: true); // [10px 20px]
// Global alias still works
join(10px 20px, 30px 40px); Pattern: flatten two token lists with join → use append when you mean “one more item.”
Code
SCSS Examples Examples target Dart Sass 1.23+ with @use "sass:list". Open View Compiled CSS for verified output (matches official Sass docs samples).
1. Flatten 2. Comma lists 3. Separator 4. Brackets 5. vs append Example 1 — Flatten Two Space Lists (Official Docs) Merge spacing tokens into one four-item list.
@use "sass:list";
@debug list.join(10px 20px, 30px 40px); // 10px 20px 30px 40px
.box {
margin: list.join(10px 20px, 30px 40px);
} .box {
margin: 10px 20px 30px 40px;
} How It Works Both inputs are space-separated lists.auto keeps the space separator.Result length is 4 — fully flattened.Useful when combining partial spacing scales.Example 2 — Flatten Comma-Separated Color Lists (Official Docs) Comma lists stay comma-separated under auto.
@use "sass:list";
@debug list.join((blue, red), (#abc, #def)); // blue, red, #abc, #def
.palette {
--colors: #{list.join((blue, red), (#abc, #def))};
} .palette {
--colors: blue, red, #abc, #def;
} How It Works Parentheses create comma-separated lists.Join flattens both into four colors.Separator stays comma from $list1.Custom property stores the finished list string.Example 3 — Force $separator (Official Docs) Override the result separator explicitly.
@use "sass:list";
@debug list.join(10px, 20px); // 10px 20px
@debug list.join(10px, 20px, $separator: comma); // 10px, 20px
@debug list.join((blue, red), (#abc, #def), $separator: space); // blue red #abc #def
.forced {
--space: #{list.join(10px, 20px)};
--comma: #{list.join(10px, 20px, $separator: comma)};
--colors: #{list.join((blue, red), (#abc, #def), $separator: space)};
} .forced {
--space: 10px 20px;
--comma: 10px, 20px;
--colors: blue red #abc #def;
} How It Works Two singles default to a space list under auto.$separator: comma forces commas.$separator: space rewrites comma inputs into spaces.Also allowed: slash (see list.slash() ).Example 4 — Inherit or Force Brackets (Official Docs) Bracketed $list1 keeps brackets; or force them with $bracketed: true.
@use "sass:list";
@use "sass:meta";
@debug list.join([10px], 20px); // [10px 20px]
@debug list.join(10px, 20px, $bracketed: true); // [10px 20px]
.brackets {
--from-list: #{meta.inspect(list.join([10px], 20px))};
--forced: #{meta.inspect(list.join(10px, 20px, $bracketed: true))};
--check: #{list.is-bracketed(list.join(10px, 20px, $bracketed: true))};
} .brackets {
--from-list: [10px 20px];
--forced: [10px 20px];
--check: true;
} How It Works $bracketed: auto copies brackets from $list1.$bracketed: true forces square brackets on plain inputs.meta.inspect keeps the […] visible.is-bracketed confirms the forced result.Example 5 — join Flattens, append Nests Same inputs, different structure — pick the helper that matches intent.
@use "sass:list";
@use "sass:meta";
.compare {
--join: #{meta.inspect(list.join(10px 20px, 30px 40px))};
--append: #{meta.inspect(list.append(10px 20px, 30px 40px))};
--join-len: #{list.length(list.join(10px 20px, 30px 40px))};
--append-len: #{list.length(list.append(10px 20px, 30px 40px))};
} .compare {
--join: 10px 20px 30px 40px;
--append: 10px 20px (30px 40px);
--join-len: 4;
--append-len: 3;
} How It Works Join produces four flat items.Append keeps three top-level items; the third is nested.Lengths make the difference obvious (4 vs 3).Rule: two lists → join; one value → append. Edge Cases & Pitfalls Most join bugs are using it like append, misunderstanding auto separator/brackets, or forgetting singles are lists.
append Do not join to “append” one value If that value is a list, join flattens it. Prefer list.append.
auto $separator: auto prefers $list1 Then $list2, then space. Force comma / space / slash when you need certainty.
brackets $bracketed: auto follows $list1 Only the first list’s brackets are inherited. Pass true to force […].
singles Singles are one-item lists list.join(10px, 20px) is valid — both sides are lists of length 1.
Toolchain
Sass Support Prefer the module form with Dart Sass 1.23+. Global join() remains for older call sites.
API Status list.join()Dart Sass 1.23+ via @use "sass:list" Global join() Available (prefer module form in new code) $separatorauto, comma, space, slashLibSass / Ruby Sass No sass:list module — use global join() if needed
Compile with the Dart Sass CLI .
Remember
Key Takeaways Flattens two lists into one new list.
Use append when adding a single value (especially if it might be a list).
$separator / $bracketed control the result shape.
Prefer list.join after @use "sass:list".
One line: when you need one flat list from two lists, call list.join($list1, $list2).
Practice
Compile Notes Practical checklist:
1. @use "sass:list"
2. Use join to flatten two lists
3. Use append to add one value
4. Pass $separator when auto is ambiguous
5. Pass $bracketed: true when CSS needs […] Frequently Asked Questions What does Sass list.join() do? list.join($list1, $list2) returns a new list with every element of $list1 followed by every element of $list2. Example: list.join(10px 20px, 30px 40px) is 10px 20px 30px 40px.
Should I use list.join or list.append to add one value? Official docs recommend list.append() for a single value. If that value is itself a list, join flattens it into the result; append nests it as one item.
What does $separator: auto mean? Auto uses $list1’s separator if it has one, else $list2’s, else space. You can force comma, space, or slash.
What does $bracketed: auto mean? Auto keeps brackets if $list1 is bracketed. Pass true to force […], or a falsey value to remove brackets.
Can I still call join() without the list. prefix? Yes. Global join($list1, $list2, …) still works. New projects should prefer list.join() after @use "sass:list".
Which compilers support sass:list? Built-in modules with @use need Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:list the same way—use the global join() name there if you must.
Next: Sass list.length() Count how many items (or map pairs) a list has.
list.length() → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion