Sass list.join()

Beginner
12 min read
Updated: Nov 2026
5 examples
Dart Sass 1.23+

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

SCSS
@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.”

Separator & Brackets

How the optional arguments behave:

ArgumentMeaning
$separator: autoUse $list1’s separator if any, else $list2’s, else space
comma / space / slashForce that separator on the result
$bracketed: autoKeep brackets if $list1 is bracketed
$bracketed: true / falseyForce […], or strip brackets
vs list.appendjoin flattens; append nests a list value
Check brackets afterward.

Use list.is-bracketed() to confirm the result shape after $bracketed: true.

SCSS Examples

Examples target Dart Sass 1.23+ with @use "sass:list". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Flatten Two Space Lists (Official Docs)

Merge spacing tokens into one four-item list.

SCSS
@use "sass:list";

@debug list.join(10px 20px, 30px 40px); // 10px 20px 30px 40px

.box {
  margin: list.join(10px 20px, 30px 40px);
}

How It Works

  1. Both inputs are space-separated lists.
  2. auto keeps the space separator.
  3. Result length is 4 — fully flattened.
  4. Useful when combining partial spacing scales.

Example 2 — Flatten Comma-Separated Color Lists (Official Docs)

Comma lists stay comma-separated under auto.

SCSS
@use "sass:list";

@debug list.join((blue, red), (#abc, #def)); // blue, red, #abc, #def

.palette {
  --colors: #{list.join((blue, red), (#abc, #def))};
}

How It Works

  1. Parentheses create comma-separated lists.
  2. Join flattens both into four colors.
  3. Separator stays comma from $list1.
  4. Custom property stores the finished list string.

Example 3 — Force $separator (Official Docs)

Override the result separator explicitly.

SCSS
@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)};
}

How It Works

  1. Two singles default to a space list under auto.
  2. $separator: comma forces commas.
  3. $separator: space rewrites comma inputs into spaces.
  4. Also allowed: slash (see list.slash()).

Example 4 — Inherit or Force Brackets (Official Docs)

Bracketed $list1 keeps brackets; or force them with $bracketed: true.

SCSS
@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))};
}

How It Works

  1. $bracketed: auto copies brackets from $list1.
  2. $bracketed: true forces square brackets on plain inputs.
  3. meta.inspect keeps the […] visible.
  4. is-bracketed confirms the forced result.

Example 5 — join Flattens, append Nests

Same inputs, different structure — pick the helper that matches intent.

SCSS
@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))};
}

How It Works

  1. Join produces four flat items.
  2. Append keeps three top-level items; the third is nested.
  3. Lengths make the difference obvious (4 vs 3).
  4. 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.

Sass Support

Prefer the module form with Dart Sass 1.23+. Global join() remains for older call sites.

APIStatus
list.join()Dart Sass 1.23+ via @use "sass:list"
Global join()Available (prefer module form in new code)
$separatorauto, comma, space, slash
LibSass / Ruby SassNo sass:list module — use global join() if needed

Compile with the Dart Sass CLI.

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).

Compile Notes

Practical checklist:

checklist.txt
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

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.
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.
Auto uses $list1’s separator if it has one, else $list2’s, else space. You can force comma, space, or slash.
Auto keeps brackets if $list1 is bracketed. Pass true to force […], or a falsey value to remove brackets.
Yes. Global join($list1, $list2, …) still works. New projects should prefer list.join() after @use "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() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful