Sass list.join() Function

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:list · Dart Sass 1.23+

What You’ll Learn

list.join() belongs to the built-in sass:list module. It merges two lists into one flat list. This page covers separators, brackets, when to prefer list.append, Dart Sass support, and five compiled examples.

01

Concept

Merge two lists

02

Module

@use "sass:list"

03

Separator

auto / space / comma

04

Brackets

$bracketed

05

vs append

Flatten vs nest

06

Practice

5 examples

What Is list.join()?

Think of two stacks of tokens—spacing scales, font families, or color names. You want one list that contains every item from both. list.join builds that combined list at compile time.

  • list.join(10px 20px, 30px 40px)10px 20px 30px 40px
  • list.join((blue, red), (#abc, #def))blue, red, #abc, #def
  • list.join(10px, 20px, $separator: comma)10px, 20px
💡
Beginner tip

Official docs warn: because a single value counts as a one-item list, you can join a value onto a list—but if that value is itself a list, join flattens it. Prefer list.append when you mean “add one item.”

📝 Syntax

Load the list module, then call the function:

styles.scss
@use "sass:list";

list.join($list1, $list2, $separator: auto, $bracketed: auto)

Parameters

ParameterTypeDefaultDescription
$list1List (or map / single value)First list—its items come first in the result.
$list2List (or map / single value)Second list—its items are appended after $list1.
$separatorauto | space | comma | slashautoauto prefers $list1’s separator, else $list2’s, else space. Other values force that separator.
$bracketedauto | boolean-ishautoauto keeps brackets if $list1 is bracketed. Truthy forces […]; falsey removes brackets.

Return value

TypeResult
ListA new list with all elements of $list1 followed by all of $list2

📦 Loading sass:list

styles.scss
// Recommended — namespaced
@use "sass:list";
$all: list.join(10px 20px, 30px 40px);

// Optional — bring members into scope
@use "sass:list" as *;
$all: join(10px 20px, 30px 40px);

// Optional — custom namespace
@use "sass:list" as l;
$all: l.join(10px 20px, 30px 40px);
⚠️
Put @use first

Keep @use "sass:list"; near the top of the file, before most other rules.

🔍 list.join vs list.append

This is the most important beginner trap. Both can look like “add more values,” but they treat a list-valued second argument differently.

styles.scss
@use "sass:list";
@use "sass:meta";

// join flattens both sides into one list
$flat: list.join(10px 20px, 30px 40px);
// → 10px 20px 30px 40px

// append nests the second value as a single item
$nested: list.append(10px 20px, 30px 40px);
// → 10px 20px (30px 40px)
list.joinlist.append
Best forCombining two listsAdding one value
If 2nd arg is a listFlattens items inNests as one item
Official adviceUse for mergePrefer for “push one”

📋 Separators and Brackets

$separator and $bracketed are independent. You can force a comma separator, square brackets, or both.

styles.scss
@use "sass:list";

// Force comma separator
list.join(10px, 20px, $separator: comma); // 10px, 20px

// Inherit brackets from $list1
list.join([10px], 20px); // [10px 20px]

// Force brackets on a plain join
list.join(10px, 20px, $bracketed: true); // [10px 20px]

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS only contains the finished list values (for example in margin or font-family).

Implementation@use "sass:list"Global join()
Dart Sass (1.23+)Yes — preferredYes
LibSassNo built-in modulesYes (legacy)
Ruby SassNo built-in modulesYes (legacy)

⚡ Quick Reference

GoalCode
Import list@use "sass:list";
Merge space listslist.join(10px 20px, 30px 40px)
Force commalist.join(10px, 20px, $separator: comma)
Keep / add bracketslist.join([10px], 20px) or $bracketed: true
Add one valuelist.append($list, $val) (not join)
Legacy globaljoin($list1, $list2, …)

Examples Gallery

Each example uses @use "sass:list". Open View Compiled CSS for verified Dart Sass output (official samples where noted).

📚 Getting Started

Official docs samples for merging space and comma lists.

Example 1 — Merge Space and Comma Lists (Official Docs)

Join two lists; separators follow the inputs when $separator is auto.

styles.scss
@use "sass:list";

@debug list.join(10px 20px, 30px 40px);              // 10px 20px 30px 40px
@debug list.join((blue, red), (#abc, #def));         // blue, red, #abc, #def

.demo {
  margin: #{list.join(10px 20px, 30px 40px)};
  --colors: #{list.join((blue, red), (#abc, #def))};
}

How It Works

Space lists stay space-separated; comma lists stay comma-separated when both sides share that style and $separator is left at auto.

Example 2 — Force a Separator (Official Docs)

Override the separator even when joining single values or mixed lists.

styles.scss
@use "sass:list";
@use "sass:meta";

@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

.sep {
  --a: #{meta.inspect(list.join(10px, 20px))};
  --b: #{meta.inspect(list.join(10px, 20px, $separator: comma))};
  --c: #{meta.inspect(list.join((blue, red), (#abc, #def), $separator: space))};
}

How It Works

Single values default to a space-separated join. Passing $separator: comma or space forces the separator you want.

📈 Practical Patterns

Brackets, padding scales, and join vs append.

Example 3 — Inherit or Force Brackets (Official Docs)

Bracketedness comes from $list1 by default, or from $bracketed.

styles.scss
@use "sass:list";
@use "sass:meta";

@debug list.join([10px], 20px); // [10px 20px]
@debug list.join(10px, 20px, $bracketed: true); // [10px 20px]

.br {
  --from-brack: #{meta.inspect(list.join([10px], 20px))};
  --force-on: #{meta.inspect(list.join(10px, 20px, $bracketed: true))};
  --force-off: #{meta.inspect(list.join([10px], 20px, $bracketed: false))};
}

How It Works

Starting from a bracketed $list1 keeps brackets. You can also force them on or strip them with $bracketed: true / false. Confirm with list.is-bracketed().

Example 4 — Combine Spacing Scales for Padding

Merge two design-token lists into one CSS shorthand.

styles.scss
@use "sass:list";

$pad: 0.5rem 1rem;
$extra: 1.5rem 2rem;

$fonts-a: Helvetica, Arial;
$fonts-b: Roboto, sans-serif;

.box {
  padding: list.join($pad, $extra);
}

.card {
  font-family: list.join($fonts-a, $fonts-b);
}

How It Works

Space lists become a four-value padding shorthand. Comma font stacks stay comma-separated when both sides use commas.

Example 5 — Flatten with Join, Nest with Append

See the structural difference side by side.

styles.scss
@use "sass:list";
@use "sass:meta";

$nested: list.append(10px 20px, 30px 40px);
$flat: list.join(10px 20px, 30px 40px);

.compare {
  --nested: #{meta.inspect($nested)};
  --flat: #{meta.inspect($flat)};
}

How It Works

append keeps 30px 40px as one nested list item. join unpacks both sides into four sibling values—usually what you want when combining scales.

🚀 Real-World Use Cases

  • Spacing / sizing scales — merge token lists into longer shorthands.
  • Font stacks — combine brand fonts with system fallbacks.
  • Color or name catalogs — concatenate theme lists for loops.
  • Bracketed track lists — build grid-related lists with $bracketed.
  • Mixin APIs — accept two partial lists and join them before emitting CSS.

🧠 How Compilation Works

1

Write SCSS

Call list.join($list1, $list2, …) after @use "sass:list".

Source
2

Merge items

Dart Sass copies every item from both lists into one new list.

Compile
3

Apply options

$separator and $bracketed shape how the result is stored.

Options
4

CSS sees the list

Properties like padding or font-family receive the finished values.

⚠️ Common Pitfalls

  • Using join instead of append — a list-valued “extra” gets flattened.
  • Unexpected separatorauto follows $list1 first; force it when unsure.
  • Forgetting brackets — only $list1 (or $bracketed) controls […].
  • Forgetting @uselist.join needs sass:list.
  • Mutating in place — join returns a new list; reassign if you store it.

💡 Best Practices

✅ Do

  • Use @use "sass:list" and list.join() in new SCSS
  • Prefer list.append when adding a single value
  • Set $separator explicitly when lists may differ
  • Use $bracketed when CSS structure needs […]
  • Prefer Dart Sass for built-in modules

❌ Don’t

  • Expect the browser to evaluate list.join
  • Use join as a casual “push one item” helper
  • Assume $list2’s brackets win over $list1
  • Rely on LibSass for @use "sass:list"
  • Forget to reassign when updating a stored list variable

Key Takeaways

Knowledge Unlocked

Five things to remember about list.join()

Flatten two lists—control separator and brackets; use append for one item.

5
Core concepts
📦 02

Module

sass:list

@use
🔢 03

Behavior

flattens both

Rule
04

Add one

use list.append

Safe
05

Prefer

Dart Sass 1.23+

Tooling

❓ 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.
Did you know?

Because individual values count as single-element lists, list.join(10px, 20px) is a valid way to build a two-item list from scratch. Still prefer list.append when your second argument might already be a list.

Conclusion

list.join() merges two Sass lists into one flat list. Load it through sass:list, set $separator and $bracketed when you need control, and reach for list.append when you only want to add a single item.

Continue with list.length() or explore list.append().

Next: list.length()

You learned list.join()—next, count list items with list.length().

list.length() →

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.

5 people found this page helpful