Sass List Functions
Sass List Functions
Sass List Functions help you create, read, modify, and loop through lists.
Lists are extremely useful for spacing systems, breakpoints, colors, utility classes, and grids.
🔹 What Is a List in Sass?
A list is a collection of values separated by spaces or commas.
✔ Both are valid lists.
🔹 Common Sass List Functions
1️⃣ length()
Returns the number of items in a list.
✔ Output:
2️⃣ nth()
Returns the item at a specific position (1-based index).
✔ Output:
3️⃣ set-nth()
Replaces an item at a given position.
✔ Output:
4️⃣ append()
Adds an item to a list.
✔ Output:
5️⃣ join()
Combines two lists.
✔ Output:
6️⃣ index()
Returns the position of a value.
✔ Output:
(Returns null if not found)
7️⃣ zip()
Combines multiple lists into pairs.
✔ Output:
8️⃣ is-bracketed()
Checks if a list uses square brackets.
✔ Output:
9️⃣ list-separator()
Returns the list separator.
✔ Output:
🔹 Looping Through a List (@each)
✔ Output:
🔹 Real-Life Example (Spacing Utilities)
❗ Important Notes
✔ Sass lists are 1-based indexed
✔ Lists can be nested
✔ Space-separated lists are more common
✔ Use lists with loops for utility classes
📌 Summary
-
Lists store multiple values
-
Useful for grids, spacing, breakpoints
-
Powerful functions available
-
Works great with loops
