Sass maps store key/value pairs for easy lookups. This page covers writing maps, quoted keys, map.get / set / merge, @each loops, immutability, and five compiled examples.
01
Pairs
key : value
02
Lookup
map.get
03
Update
set / merge
04
@each
Loop pairs
05
Quoted keys
Safer default
06
Practice
5 examples
Concept
What Are Sass Maps?
Official docs: maps hold pairs of keys and values so you can look up a value by its key. They are written (key: value, …). Keys must be unique; values may be duplicated. Unlike lists, maps must use parentheses. An empty map is ().
Any Sass value can be a key; equality uses ==.
Maps are not valid CSS by themselves—use helpers or loops to emit CSS.
Every map also counts as a list of two-element key/value lists.
Prefer quoted string keys to avoid color-name traps.
💡
Beginner tip
Think of a map as a design-token dictionary: names on the left, concrete CSS values on the right. Look up one token with map.get, or generate many rules with @each.
Official docs: most of the time, use quoted strings for keys. Some values that look like unquoted strings—especially color names like red—are other types. Quoting avoids confusing lookup bugs later.
API
🧮 Using Maps
Load @use "sass:map" for helpers:
Need
Function
Get a value
map.get($map, $key)
Set / replace
map.set($map, $key, $value)
Combine maps
map.merge($map1, $map2)
Check a key
map.has-key($map, $key)
All keys / values
map.keys() / map.values()
Loop pairs with @each: @each $key, $value in $map { … }.
Relationship
🔗 Maps Count as Lists
Official docs: every map is also a list containing a two-element list for each pair. For example, (1: 2, 3: 4) counts as (1 2, 3 4). That is why empty () is both an empty map and an empty list.
Safety
🔒 Immutability
Official docs: map contents never change in place. map.set and map.merge return new maps. Reassign when you need updated state: $config: map.merge($config, ("theme": dark));
Cheat Sheet
⚡ Quick Reference
Goal
Code
Write a map
("sm": 480px, "md": 768px)
Look up
map.get($map, "md")
Add a key
map.set($map, "lg", 1024px)
Merge
map.merge($a, $b) (second wins on clashes)
Loop pairs
@each $k, $v in $map { … }
Missing key
map.get → null (falsey)
Hands-On
Examples Gallery
Each example turns map data into CSS or inspectable values. Open View Compiled CSS for verified output.
📚 Getting Started
Look up values and generate rules from pairs.
Example 1 — map.get, Keys & Values
Official-docs style font-weight map with lookup helpers.
Sass maps are the go-to structure for named design tokens. Quote your keys, look up with map.get, update immutably with set / merge, and generate CSS with @each.