map.merge($map1, $map2) returns a new map with all keys from both maps. Matching keys take $map2’s value (shallow—nested maps are replaced, not recursed). Load it with @use "sass:map" on Dart Sass 1.23+. Legacy global name: map-merge.
Dart Sass also allows map.merge($map, $keys..., $overlay) to shallow-merge into a nested target. Missing mid-path keys become empty maps along the way.
Need recursive merge?
Use map.deep-merge() when colliding nested maps should combine sibling keys instead of replacing the whole branch.
Combines two maps into a new one; $map2 wins conflicts.
Shallow by default — nested maps replace, they do not recurse.
Nested path form merges an overlay into one branch.
Prefer map.merge over deprecated global map-merge.
One line: when two maps must combine shallowly, call map.merge($base, $overrides).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:map"
2. Use merge for flat / shallow combines
3. Use deep-merge when nested siblings must survive
4. Nested path: map.merge($map, $k1, $k2, $overlay)
5. Reassign: $map: map.merge($map, $over)
Frequently Asked Questions
map.merge($map1, $map2) returns a new map with all keys from both maps. If both share a key, $map2’s value wins. Nested map values are replaced wholesale—not merged recursively (use map.deep-merge for that).
No. It returns a new map. Reassign if you need to keep the result: $config: map.merge($config, $overrides).
map.merge is shallow: a nested map at a colliding key is replaced entirely by $map2’s value. map.deep-merge recursively merges nested maps so sibling keys inside both branches survive.
Yes. map-merge($map1, $map2) is the older global name, but Dart Sass deprecates global built-ins toward Sass 3.0. Prefer map.merge after @use "sass:map". Nested path merge with extra keys needs Dart Sass and the module API.
Yes on Dart Sass: map.merge($map, $key1, $key2, ..., $overlay) walks the keys, then shallow-merges $overlay into that nested target. Missing mid-path keys become empty maps.
$map2 always wins for that key. Keys that only exist in $map1 keep their values and relative order; new keys from $map2 are appended at the end.