Sass list.append()

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

Definition and Usage

list.append($list, $val, $separator: auto) returns a copy of $list with $val added at the end. Load it with @use "sass:list" on Dart Sass 1.23+. Global alias: append().

Official note: unlike list.join(), if $val is itself a list it is nested inside the result rather than flattened.

Official samples.

list.append(10px 20px, 30px) → 10px 20px 30px. list.append((blue, red), green) → blue, red, green. list.append(10px 20px, 30px 40px) → 10px 20px (30px 40px).

Lists everywhere.

Single values count as one-item lists, and maps count as lists of key/value pairs — so append works on those shapes too.

Syntax

SCSS
@use "sass:list";

list.append(10px 20px, 30px);                       // 10px 20px 30px
list.append((blue, red), green);                    // blue, red, green
list.append(10px 20px, 30px 40px);                  // 10px 20px (30px 40px)
list.append(10px, 20px, $separator: comma);         // 10px, 20px
list.append((blue, red), green, $separator: space); // blue red green

// Global alias still works
append(10px 20px, 30px);

Pattern: grow spacing / color tokens with append → use join only when you want to flatten two lists together.

Separator & Nest vs Join

How the arguments behave:

Argument / ideaMeaning
$separator: autoKeep $list’s separator (or space if it has none)
comma / space / slashForce that separator on the returned list
NestingIf $val is a list, it becomes one nested item
vs list.joinjoin flattens two lists; prefer append for one value
Do not use join to “append” one value.

Official docs: if that value is a list, join concatenates it. Use list.append() when you mean “add one item.”

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 — Append to a Space-Separated List (Official Docs)

Add a third spacing token onto 10px 20px.

SCSS
@use "sass:list";

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

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

How It Works

  1. Start list is space-separated.
  2. auto separator keeps spaces.
  3. Result is a three-item margin list.
  4. Original list is not mutated — you get a copy.

Example 2 — Append to a Comma-Separated List (Official Docs)

Grow a color list while keeping commas.

SCSS
@use "sass:list";

@debug list.append((blue, red), green); // blue, red, green

.palette {
  --colors: #{list.append((blue, red), green)};
}

How It Works

  1. Parentheses make a comma-separated list.
  2. green is appended as the third item.
  3. Separator stays comma under auto.
  4. Custom property stores the finished list string.

Example 3 — Nested List vs join (Official Docs)

Appending a list nests it. Use meta.inspect / length to see the structure (CSS alone flattens).

SCSS
@use "sass:list";
@use "sass:meta";

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

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

.report {
  --length: #{list.length($nested)};
  --inspect: #{meta.inspect($nested)};
  --join: #{meta.inspect(list.join(10px 20px, 30px 40px))};
}

How It Works

  1. Append keeps three top-level items; the third is a nested pair.
  2. Length is 3, not 4.
  3. join flattens to four items instead.
  4. Rule of thumb: one value → append; two lists → join.

Example 4 — Force $separator (Official Docs)

Override the returned list’s separator explicitly.

SCSS
@use "sass:list";

@debug list.append(10px, 20px, $separator: comma);         // 10px, 20px
@debug list.append((blue, red), green, $separator: space); // blue red green

.forced {
  --pair: #{list.append(10px, 20px, $separator: comma)};
  --colors: #{list.append((blue, red), green, $separator: space)};
}

How It Works

  1. Single values normally become a space list under auto.
  2. $separator: comma forces commas.
  3. $separator: space can rewrite a comma list into spaces.
  4. Also allowed: slash (see list.slash()).

Example 5 — Grow a List Variable

Reassign as you append — lists are immutable copies.

SCSS
@use "sass:list";

$base: 8px 16px;
$grow: list.append($base, 24px);
$grow: list.append($grow, 32px);

.stack {
  padding: $grow;
}

How It Works

  1. Start with two spacing steps.
  2. Each append returns a new list.
  3. Reassign $grow to keep extending it.
  4. Final padding is four space-separated values.

Edge Cases & Pitfalls

Most append bugs are expecting join-style flattening, forgetting to reassign, or misunderstanding $separator.

nest

Appending a list nests it

list.append(10px 20px, 30px 40px) has length 3. Use join when you want four flat items.

immut

Reassign to grow a variable

Write $sizes: list.append($sizes, 30px); — calling append alone does not update $sizes.

sep

$separator values are limited

Only auto, comma, space, and slash are allowed.

css

CSS output can hide nesting

Inspect with meta.inspect / list.length when teaching nested structure.

Sass Support

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

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

Compile with the Dart Sass CLI.

Key Takeaways

  • Adds one value to the end and returns a new list.
  • Nests list values — use join only when you want to flatten.
  • $separator can force comma, space, or slash.
  • Reassign when growing a variable over multiple steps.

One line: when you need one more item on a list, call list.append($list, $val).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:list"
2. Prefer list.append for a single new item
3. Use list.join only to flatten two lists
4. Pass $separator when you need comma / space / slash
5. Reassign: $list: list.append($list, $val)

Frequently Asked Questions

list.append($list, $val, $separator: auto) returns a copy of $list with $val added at the end. Example: list.append(10px 20px, 30px) is 10px 20px 30px.
append adds one value (and nests it if that value is a list). join concatenates two lists element-by-element. Official docs recommend append when adding a single value.
It sets the returned list’s separator: comma, space, or slash. The default auto keeps $list’s separator (or space if $list has none).
No. Sass lists are immutable for these helpers—you get a new list. Reassign if you want to keep growing a variable: $sizes: list.append($sizes, 30px);
Yes. Global append($list, $val) still works. New projects should prefer list.append() 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 append() name there if you must.

Next: Sass list.index()

Find the 1-based index of a value in a list.

list.index() →

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