Sass lists hold a sequence of values. This page covers separators, brackets, 1-based indexes, nth / append / index, @each, immutability, argument lists, and five compiled examples.
01
Separators
space / comma
02
Brackets
[ … ]
03
Indexes
Start at 1
04
@each
Loop items
05
Immutable
append returns new
06
Practice
5 examples
Concept
What Are Sass Lists?
Official docs: lists contain a sequence of other values. Elements can be separated by commas (Helvetica, Arial, sans-serif), spaces (10px 15px 0 0), or slashes—as long as the separator is consistent within the list.
Unlike many languages, Sass lists do not require brackets. Any expressions separated with spaces or commas count as a list. Square brackets ([line1 line2]) are allowed and especially useful for values like grid-template-columns.
Use parentheses to nest lists or disambiguate separators.
Single values act like one-element lists for most list functions.
Empty unbracketed () is not valid CSS in a property value.
Indexes start at 1; -1 is the last item.
💡
Beginner tip
Think of a Sass list as a CSS value that already looks like a sequence—font stacks, padding shorthands, or grid tracks—then use sass:list when you need to read or build those sequences in code.
Official docs: slash-separated lists represent values like font: 12px/30px or modern color alpha syntax. Because / historically meant division, you cannot reliably write slash lists as literals today. Create them with list.slash() while stylesheets migrate to math.div().
Official docs: Sass lists never change in place. list.append and friends return new lists. That avoids sneaky bugs when the same list is shared. To grow a collection, reassign: $prefixes: list.append($prefixes, $next);
Advanced
📦 Argument Lists
When a mixin or function takes arbitrary arguments with $args..., you get a special argument list. It behaves like a normal list of positional values, and keyword arguments are available as a map via meta.keywords($args).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Space list
10px 12px 16px
Comma list
Helvetica, Arial, sans-serif
Bracketed
[line1, line2]
2nd item
list.nth($list, 2)
Last item
list.nth($list, -1)
Append
list.append($list, $val)
Validate membership
@if not list.index($allowed, $val)
Slash list
list.slash(12px, 30px)
Hands-On
Examples Gallery
Each example shows a common list pattern. Open View Compiled CSS for verified output.
📚 Getting Started
Read items, detect separators, and generate utilities.
Example 1 — nth, Length & Separators
Pull items by index and inspect how a list is separated.
.demo {
--pfx: moz ms;
--slash: 12px / 30px;
}
pre span.stx-string {
color: #080;
}
pre span.stx-comment {
color: #800;
}
pre span.stx-variable {
color: #60b;
}
How It Works
Reassigning $prefixes accumulates values because lists are immutable. meta.keywords($args) turns named mixin arguments into a map for @each.
Applications
🚀 Real-World Use Cases
Utility generators — sizes, spacings, or breakpoints in one list.
Font stacks — comma-separated family lists.
Grid tracks — bracketed line-name lists.
Validation — allow-lists checked with list.index.
Flexible mixins — $args... plus meta.keywords.
🧠 How Compilation Works
1
Parse the sequence
Detect space, comma, slash, brackets, and nesting.
Parse
2
Read or build
Use nth / append / index, or walk items with @each.
Work
3
Emit CSS
Write separators and brackets the way CSS expects.
Serialize
4
✓
CSS ships
Browsers see plain sequences—Sass list APIs stay compile-time.
Watch Out
⚠️ Common Pitfalls
0-based indexes — Sass lists start at 1.
Expecting mutation — append does not change the original list.
Empty () in CSS — unbracketed empty lists are invalid property values.
Comma lists as arguments — wrap with extra parentheses when passing one list to a function.
Writing slash lists literally — use list.slash() instead of relying on /.
Pro Tips
💡 Best Practices
✅ Do
Keep separator style consistent inside one list
Use @use "sass:list" for nth / append / index
Prefer @each when generating repetitive CSS
Reassign when accumulating: $list: list.append(…)
Use bracketed lists for grid line names
❌ Don’t
Assume indexes start at 0
Ignore a null from list.index when validating
Put empty unbracketed lists into CSS properties
Mix spaces and commas in the same list
Treat slash / as a literal list separator in source
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass lists
Sequences with separators, 1-based indexes, and immutable helpers.
5
Core concepts
📋01
Sequences
space / comma
Basics
🔢02
Indexes
start at 1
API
🔄03
@each
loop items
Generate
🔒04
Immutable
append = new
Safety
✓05
$args...
argument lists
Mixins
❓ Frequently Asked Questions
A list is a sequence of values. Elements can be separated by spaces, commas, or slashes (slash lists are created with list.slash()). Brackets like [a b] are optional but useful for CSS Grid.
No. Index 1 is the first element. Negative indexes count from the end: -1 is the last element.
No. Lists are immutable. Functions like list.append() return a new list; they do not change the original. Reassign the variable if you need to update state.
Use @each $item in $list { … }. Each element is assigned to $item once per iteration.
It returns null, which is falsey—so you can use it with @if to validate allowed values.
When a mixin or function uses $args..., the collected arguments form a special list. Keyword arguments are available via meta.keywords($args).
Did you know?
Official Sass docs note that individual non-list values are treated as one-element lists by list functions—so you rarely need to wrap a single value just to call list.nth or list.append.
Sass lists are CSS-friendly sequences with space, comma, or slash separators. Read them with nth, grow them with append, validate with index, and generate styles with @each—always remembering lists are immutable.