map.deep-merge($map1, $map2) returns a new map with keys from both sides. It is identical to map.merge(), except nested map values are also merged recursively. Load it with @use "sass:map" on Dart Sass 1.27+. There is no separate global deep-merge().
Official idea.
Design systems often share nested config maps. Deep merge keeps nested keys from both maps instead of wiping a whole nested branch when the same key appears on both sides.
$map2 wins conflicts.
Matching non-map values take $map2’s value. Matching nested maps combine; nested keys from $map2 still override the same nested keys from $map1.
Immutable result.
Original maps stay unchanged. Reassign when you want to keep the merge: $config: map.deep-merge($config, $overrides);
Recursively merges nested maps instead of replacing them.
$map2 wins on conflicting non-map values and nested keys.
Ideal for theme overrides on nested design tokens.
Module only — Dart Sass 1.27+, no global helper.
One line: when nested config maps must combine, call map.deep-merge($base, $overrides).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:map"
2. Prefer deep-merge for nested theme/config maps
3. Use map.merge when a nested branch should be replaced
4. Reassign: $config: map.deep-merge($config, $over)
5. Read nested values with map.get($map, $k1, $k2, ...)
Frequently Asked Questions
map.deep-merge($map1, $map2) returns a new map combining both maps. Nested map values are merged recursively—unlike map.merge(), which replaces a whole nested map when keys collide.
Official docs: identical to map.merge(), except nested map values are also recursively merged. Shallow merge replaces the nested weights map entirely; deep-merge keeps keys from both nested maps.
For non-map values, $map2 wins. For nested maps on both sides, keys are combined and $map2’s nested values still override matching nested keys.
No. It returns a new map. Reassign if you need to keep the result: $config: map.deep-merge($config, $overrides).
No. Use map.deep-merge() after @use "sass:map" (or @use "sass:map" as * and call deep-merge()).
Dart Sass 1.27+. LibSass and Ruby Sass do not provide this deep helper—prefer current Dart Sass.