Sass list.append() Function

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

What You’ll Learn

list.append() belongs to the built-in sass:list module. It returns a copy of a list with one value added at the end. This page covers separators, nesting vs joining, module loading, Dart Sass support, and five compiled examples.

01

Concept

Add to the end

02

Module

@use "sass:list"

03

Separator

auto / comma / space

04

Nesting

Lists stay nested

05

Vs join

append ≠ join

06

Practice

5 examples

What Is list.append()?

Think of a shopping list: append means “add one more item at the bottom.” Sass does the same for space-separated or comma-separated lists while compiling your stylesheet.

  • 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)
💡
Beginner tip

The original list is not mutated. You usually reassign: $sizes: list.append($sizes, 30px); Browsers never see list.append—only the finished CSS values.

📝 Syntax

Load the list module, then call the function:

styles.scss
@use "sass:list";

list.append($list, $val, $separator: auto)

Parameters

ParameterTypeRequiredDescription
$listList (or map / single value)YesThe list to copy. Maps and single values also count as lists in Sass.
$valAnyYesThe value added at the end. If it is a list, it is nested as one item.
$separatorauto | comma | space | slashNoDefault auto keeps $list’s separator (or space if none).

Return value

TypeMeaning
ListA new list: all items from $list, then $val as the last item.

📦 Loading sass:list

Modern Sass groups list helpers into the sass:list module. Prefer the namespaced form in new code.

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

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

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

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

🔗 Separators: Space, Comma, Slash

CSS uses different separators for different jobs: spaces in margin: 10px 20px 30px, commas in font-family: Helvetica, Arial, sans-serif. $separator controls which style the returned list uses.

CallResult
list.append(10px, 20px, $separator: comma)10px, 20px
list.append((blue, red), green, $separator: space)blue red green
list.append(10px 20px, 30px) (auto)10px 20px 30px (keeps space)

📋 list.append vs list.join

Official docs: do not use list.join just to add one value—if that value is a list, join flattens it. Prefer list.append for a single add.

list.appendlist.join
JobAdd one value to the endConcatenate two lists
If $val is a listNested as one itemElements are merged in
Exampleappend(10px 20px, 30px 40px)10px 20px (30px 40px)join(10px 20px, 30px 40px)10px 20px 30px 40px

🛠 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 append()
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";
Append a lengthlist.append(10px 20px, 30px)
Append a fontlist.append((Helvetica, Arial), sans-serif)
Force commaslist.append(10px, 20px, $separator: comma)
Grow a variable$s: list.append($s, 8px);
Legacy globalappend($list, $val)

Examples Gallery

Each example uses @use "sass:list". Open View Compiled CSS to see what Dart Sass emits (official samples where noted).

📚 Getting Started

Official docs patterns for everyday CSS lists.

Example 1 — Append to a Space-Separated List (Official Docs)

Grow a margin shorthand one length at a time.

styles.scss
@use "sass:list";

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

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

.box {
  margin: $sizes;
}

How It Works

The space separator is kept (auto). Reassigning $sizes stores the longer list for the property.

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

Extend a font stack safely.

styles.scss
@use "sass:list";

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

$fonts: Helvetica, Arial;
$fonts: list.append($fonts, sans-serif);

.card {
  font-family: $fonts;
}

How It Works

Parentheses around blue, red make a comma list in SCSS. Append keeps commas when $separator is auto.

📈 Practical Patterns

Nesting, forced separators, and building token stacks.

Example 3 — Nested List When $val Is a List (Official Docs)

Appending a list nests it—it does not flatten.

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

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

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

.demo {
  --pair: #{meta.inspect($pair)};
  padding: list.nth($pair, 1) list.nth($pair, 2);
}

How It Works

The third item is the sub-list 30px 40px. Use list.join if you meant to flatten four lengths into one list.

Example 4 — Force a Separator (Official Docs)

Override the list style with $separator.

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

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

.demo {
  --comma: #{meta.inspect(list.append(10px, 20px, $separator: comma))};
  --space: #{meta.inspect(list.append((blue, red), green, $separator: space))};
}

How It Works

A single value like 10px has no separator, so auto would default to space—passing comma builds a CSS comma list on purpose.

Example 5 — Build a Spacing Scale

Start from one token and append steps for a small design scale.

styles.scss
@use "sass:list";

$gaps: 0.5rem;
$gaps: list.append($gaps, 1rem);
$gaps: list.append($gaps, 1.5rem);

.stack > * + * {
  margin-top: list.nth($gaps, 2); // 1rem
}

.radii {
  border-radius: list.append(4px 4px, 0);
}

How It Works

Repeated appends grow $gaps. Pair with list.nth when a property needs one step from the scale.

🚀 Real-World Use Cases

  • Font stacks — append a fallback family to a shared token.
  • Shorthand lists — build margin, padding, or border-radius lists.
  • Design scales — grow spacing or shadow stacks in loops and mixins.
  • Safe single adds — prefer append over join when the new item might be a list.
  • Maps as lists — Sass treats maps as lists of pairs, so list helpers can apply.

🧠 How Compilation Works

1

Write SCSS

Add @use "sass:list"; and call list.append($list, $val).

Source
2

Dart Sass runs

The list module copies $list and adds $val at the end.

Compile
3

Separator applied

auto keeps the old separator; or you force comma / space / slash.

List
4

CSS sees values

Properties receive finished lists—no list.append call remains.

⚠️ Common Pitfalls

  • Forgetting to reassignlist.append($s, 1) alone does not update $s.
  • Expecting flatten — appending a list nests it; use list.join to merge elements.
  • Wrong separator — font stacks need commas; shorthands usually need spaces.
  • Forgetting @uselist.append is undefined until you load sass:list.
  • LibSass pipelines — built-in modules need Dart Sass; use global append() carefully on legacy tooling.

💡 Best Practices

✅ Do

  • Use @use "sass:list" and list.append() in new SCSS
  • Reassign when growing a variable: $list: list.append($list, $item)
  • Choose $separator to match the CSS property
  • Prefer append over join for a single new value
  • Check results with @debug or meta.inspect while learning

❌ Don’t

  • Expect the browser to evaluate list.append
  • Use join when you meant to nest a sub-list as one item
  • Mix comma and space lists without an intentional $separator
  • Rely on LibSass for @use "sass:list"
  • Forget that single values also count as one-item lists

Key Takeaways

Knowledge Unlocked

Five things to remember about list.append()

Compile-time “add one item”—nested if that item is a list.

5
Core concepts
📦 02

Module

sass:list

@use
🔗 03

Separator

auto / comma / space

CSS
📁 04

Lists as $val

nested

Gotcha
05

Prefer

Dart Sass 1.23+

Tooling

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

Official Sass docs note that every map counts as a list of two-element pairs, and a lone value like 1px counts as a one-item list. That is why list.append(10px, 20px) works even when the first argument does not look like a multi-value list.

Conclusion

list.append() is the reliable way to add one value to the end of a Sass list at compile time. Load it through sass:list, reassign when growing tokens, pick the right $separator, and remember that a list-valued $val stays nested.

Continue with list.index() or explore math.abs() for another module-style helper.

Next: list.index()

You learned list.append()—next, find a value’s position with list.index().

list.index() →

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