list.length($list) returns how many items are in $list. Load it with @use "sass:list" on Dart Sass 1.23+. Global alias: length().
Official docs: a single value counts as a one-item list (length 1), and a map returns the number of key/value pairs. Pair with list.nth() when looping by index.
list.append(10px 20px, 30px 40px) has length 3, not 4. Use list.join() when you want a flat count.
Syntax
Syntax
SCSS
@use "sass:list";
list.length(10px); // 1
list.length(10px 20px 30px); // 3
list.length((width: 10px, height: 20px)); // 2
list.length(()); // 0
list.length([]); // 0
// Global alias still works
length(10px 20px 30px);
Pattern: read length → guard or loop 1…length with nth.
Reference
What Counts
How different shapes are counted:
Input
Length
Single value 10px
1
Space / comma list of n items
n
Map with n pairs
n (pairs, not keys alone)
() or []
0
Nested item from append
Counts as one top-level item
Brackets do not change length.
list.length([a, b, c]) is still 3. Bracketedness is a separate flag — see list.is-bracketed().
Counts top-level items in a list (or pairs in a map).
Singles are length 1; empty lists are 0.
Nested append items still count as one slot.
Prefer list.length after @use "sass:list".
One line: when you need how many items a list has, call list.length($list).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:list"
2. Remember singles have length 1
3. Maps return pair counts
4. Use length to spot append nesting vs join flattening
5. Guard empty lists before nth / set-nth
Frequently Asked Questions
list.length($list) returns how many items are in $list. Example: list.length(10px 20px 30px) is 3. A single value like 10px has length 1.
Yes. Official docs: it can return the number of pairs in a map. list.length((width: 10px, height: 20px)) is 2.
0. For example list.length(()) is 0, and list.length([]) is also 0.
No. Bracketedness is separate from length. list.length([a, b, c]) is still 3.
Yes. Global length($list) still works. New projects should prefer list.length() 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 length() name there if you must.