map.has-key($map, $key, $keys...) returns true if the map contains that key, otherwise false. With extra keys it checks a nested path the same way map.get walks nested maps. Load it with @use "sass:map" on Dart Sass 1.23+ (nested multi-key paths need a current Dart Sass release). Legacy global name: map-has-key.
Returns true/false for key or nested-path existence.
Safer than get + or when values can be falsy.
Pair with @if for optional theme/CSS output.
Prefer map.has-key over deprecated global map-has-key.
One line: when you need to know if a key exists, call map.has-key($map, $key) or map.has-key($map, $path...).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:map"
2. Use has-key for existence; get for values
3. Nested tokens: map.has-key($map, group, token)
4. Guard optional CSS with @if map.has-key(...)
5. Avoid global map-has-key in new code
Frequently Asked Questions
map.has-key($map, $key, $keys...) returns true if the map has that key, otherwise false. With extra keys (Dart Sass) it checks a nested path the same way map.get walks nested maps.
map.get returns the stored value or null. map.has-key returns true or false for existence. Use has-key when the real value might be false, 0, or null and you still need to know if the key is present.
Yes. map-has-key($map, $key) is the older global name, but Dart Sass deprecates global built-ins toward Sass 3.0. Prefer map.has-key after @use "sass:map". Nested multi-key checks need the module API.
Official docs: has-key returns false if any key in the path is missing or points to a value that is not a map—same idea as a failed nested get returning null.
No. It only checks. Pair it with map.get to read values, or with @if to emit optional CSS.
Flat two-argument checks work widely via map.has-key / map-has-key. Multi-key nested checks are Dart Sass only.