The Sass @each rule runs a block once for every item in a list or every pair in a map. It is ideal for repetitive styles that differ by a small set of values (sizes, names, tokens).
Write @each $item in $list { … }. Each element is assigned to $item in turn. Use interpolation (#{$item}) to build selectors and property values. The loop is compile-time only — browsers never see @each.
Official pattern.
Per the Sass docs: emit styles for each list element or each map key/value pair when variations are few and known up front.
@each vs @for.
Prefer @each when you already have the values. Prefer @for when you need to count a numeric range.
Pattern: collection → @each $var in … → emit CSS per item.
Reference
Loop Forms
Three common ways to write @each:
Form
Meaning
@each $item in $list
One variable per list element
@each $key, $value in $map
Key then value for every map pair
@each $a, $b, $c in $rows
Destructure each inner list (missing slots → null)
Fun fact.
Maps count as lists of key/value lists, so map looping works through the same destructuring idea — no special map-only keyword beyond naming two variables.
Also used with
Related Values
@each walks Sass collections. Learn the value types first: Lists and Maps. Inside the block you often combine interpolation and optional @if checks.
Code
SCSS Examples
Short, copy-ready snippets. Open View Compiled CSS for verified output.
Example 1 — Loop a List of Sizes
Generate matching icon utilities from one size list.
Interpolate.btn:#{$state} into :hover, :focus, :active.
One source of truth keeps theme and states in sync.
Edge Cases & Pitfalls
Most @each bugs are interpolation, output size, or choosing the wrong loop.
selectors
Build selectors with interpolation
Use #{$name} in class names. Plain $name inside a selector will not expand the way you expect.
output
Large maps grow CSS fast
Every iteration emits real CSS. Keep token sets intentional for production builds.
null
Short rows become null
Destructuring with more variables than values fills the extras with null. Guard with @if when needed.
range
Counting? Use @for
If you only need 1…n, prefer @for. Reserve @each for known lists and maps.
Toolchain
Sass Support
@each is a core Dart Sass control rule. It is not a browser CSS feature — support means your Sass compiler understands it.
Implementation
Status
Dart Sass
Supported (recommended)
LibSass / node-sass
Supported (deprecated toolchain)
Ruby Sass
Supported (end-of-life)
Browsers
N/A — only see compiled CSS
Prefer Dart Sass for new projects. SCSS and indented syntax both support @each.
Remember
Key Takeaways
Lists:@each $item in $list.
Maps:@each $key, $value in $map.
Rows: destructure with multiple variables.
Output: interpolate selectors; ship only the CSS you need.
One line: walk a list or map once, emit CSS per item at compile time.
Compile
Compile Notes
@each never reaches the browser. Conceptual flow:
flow.txt
1. Evaluate the list or map after `in`
2. Bind $item (or $key/$value / destructured fields)
3. Evaluate the block → emit CSS for this pass
4. Repeat until the collection ends
5. Final stylesheet contains only the generated rules
Frequently Asked Questions
It evaluates a block once for each element of a list, or each key/value pair in a map, assigning values to variables you name. The loop runs at compile time.
Write @each $size in $sizes { … }. Each list item is assigned to $size in turn.
Write @each $name, $value in $map { … }. The key goes to the first variable and the value to the second.
If you have a list of lists, @each $a, $b, $c in $rows assigns each inner list’s values to those variables (or null if a value is missing).
No. @each is compile-time only. Browsers see the styles generated for each iteration.
@each walks values in a list or map. @for counts through a numeric range (from/through/to). Use @each when you already have the items to style.