map.get() belongs to the built-in sass:map module. It reads a value from a map by key—or by a nested key path. This page covers missing keys (null), map-get, nested lookup (Dart Sass 1.27+), defaults with or, and five compiled examples.
01
Concept
Read by key
02
Module
@use "sass:map"
03
Missing
Returns null
04
Nested
Multi-key path
05
Legacy
map-get
06
Practice
5 examples
Concept
What Is map.get()?
Maps store named values—font weights, colors, radii. map.get is how you pull one value out so you can put it in CSS. Official docs: with only $key, you get the value for that top-level key (or null if it is missing). With extra keys, Sass walks nested maps and returns the value at the last key.
One key → top-level lookup
Several keys → nested path (Dart Sass 1.27+)
Missing key or broken path → null, not an error
💡
Beginner tip
Think of a dictionary: map.get($weights, "medium") asks for the entry named medium. Nested keys are like folders: map.get($fonts, "Helvetica", "weights", "regular").
Foundation
📝 Syntax
Load the map module, then call the function:
styles.scss
@use "sass:map";
map.get($map, $key, $keys...)
// Legacy global name (still works)
map-get($map, $key)
Parameters
Parameter
Type
Required
Description
$map
Map
Yes
Map to read from. Not modified.
$key
Any
Yes
First key. Alone, this is the top-level key to look up.
$keys...
Any (variadic)
No
Extra keys for nested lookup. The last key is the value you want (Dart Sass 1.27+).
Return value
Type
Result
Any
The stored value when the key (or nested path) exists
null
When the key is missing, or a nested step is missing / not a map
Modules
📦 Loading sass:map
styles.scss
// Recommended — namespaced
@use "sass:map";
$primary: map.get($theme, "colors", "primary");
// Optional — bring members into scope
@use "sass:map" as *;
$primary: get($theme, "colors", "primary");
// Optional — custom namespace
@use "sass:map" as m;
$primary: m.get($theme, "colors", "primary");
// Legacy global (flat keys)
$medium: map-get($font-weights, "medium");
⚠️
Module vs legacy
Prefer map.get with @use "sass:map". Keep map-get for older snippets. Nested multi-key lookup is a modern Dart Sass feature—use the module API.
Details
🔍 Flat Lookup vs Nested Path
Official behavior splits cleanly into two cases:
No extra keys — return the value for $key, or null
Extra keys — walk left to right through nested maps; return the value for the last key, or null if any step fails
Both accept the same key-path style. Choose based on whether you need the value or a yes/no answer.
map.get
map.has-key
Returns
Value or null
true / false
Best for
Emitting CSS tokens
Guards and conditionals
Value is false or null
Hard to tell from “missing” with get alone
Clearly says if the key exists
Nested keys
Dart Sass 1.27+
Dart Sass 1.27+
💡
Defaults with or
A common pattern: map.get($map, $key) or $fallback. Remember that false, null, and empty string are all falsy in Sass—so for flags that may be false, prefer map.has-key first.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS only contains the finished values you read from the map.
Implementation
Flat map.get / map-get
Nested multi-key
Dart Sass
Yes (@use since 1.23+)
Yes since 1.27.0
LibSass
Use global map-get
No nested multi-key API
Ruby Sass
Legacy map-get
No—prefer Dart Sass
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import map
@use "sass:map";
Read top-level
map.get($map, "medium")
Read nested
map.get($map, "a", "b", "c")
Default value
map.get($map, $key) or $fallback
Key exists?
map.has-key($map, $key)
Legacy name
map-get($map, $key)
Nested keys since
Dart Sass 1.27+
Hands-On
Examples Gallery
Each example uses @use "sass:map". Open View Compiled CSS for verified Dart Sass output (official samples where noted).
📚 Getting Started
Official docs samples: flat get and nested get.
Example 1 — Top-Level Key (Official Docs)
Read a weight when it exists; get null when it does not.
map.get returns null for extra-bold, so or 400 supplies the default. Perfect for optional theme overrides.
Applications
🚀 Real-World Use Cases
Design tokens — read colors, spacing, and radii from a theme map into CSS.
Typography scales — pull a single weight from a nested font map (docs sample).
Component APIs — accept a config map and get only the options you need.
Safe defaults — map.get(...) or $fallback for optional overrides.
Guarded mixins — pair with map.has-key before using a nested branch.
🧠 How Compilation Works
1
Write SCSS
Call map.get($map, $key, $keys...) after @use "sass:map".
Source
2
Resolve the path
Dart Sass looks up the key or walks nested maps to the last key.
Compile
3
Return a value
You get the stored value, or null if the path fails.
Result
4
✓
CSS sees tokens
Only the colors, sizes, or numbers you interpolate remain.
Watch Out
⚠️ Common Pitfalls
Treating null as an error — missing keys are normal; add a default or check has-key.
Using or with boolean flags — a stored false is falsy, so a fallback may fire incorrectly.
Nested keys on old tooling — multi-key map.get needs Dart Sass 1.27+.
Expecting mutation — get only reads; use map.set / merge helpers to change maps.
Forgetting quotes — string keys like "medium" must match how the map was written.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:map" and map.get()
Pass the full nested path when reading deep tokens
Pair with map.has-key for optional branches
Use or $fallback for missing optional values
Prefer Dart Sass 1.27+ for nested design-system maps
❌ Don’t
Expect the browser to evaluate map.get
Assume missing keys throw—they return null
Use or blindly when values may be false
Rely on nested multi-key get under LibSass
Confuse read (get) with write (set / merge)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about map.get()
Read by key or path—missing returns null; nested needs Dart Sass 1.27+.
5
Core concepts
📝01
Call
map.get($map, $key, $keys...)
API
📦02
Module
sass:map
@use
🔢03
Missing
returns null
Rule
❓04
Nested
multi-key path
Safe
✓05
Legacy
map-get still works
Tooling
❓ Frequently Asked Questions
map.get($map, $key, $keys...) returns the value for a key. With one key it reads the top level. With more keys (Dart Sass 1.27+) it walks nested maps and returns the value at the last key.
It returns null. That is not an error. Use map.has-key() when you need a true/false check, or combine with or for a default: map.get($map, $key) or $default.
Yes. map-get($map, $key) is the older global name. Prefer map.get after @use "sass:map". Nested key paths with more than two arguments need Dart Sass 1.27+ and the module API.
map.get returns the stored value (or null). map.has-key returns true or false for whether the key exists—useful when the real value might be null or false.
Two-argument get works widely via map-get / map.get. Passing multiple keys for nested lookup is Dart Sass 1.27+ only. Prefer current Dart Sass for design-system maps.
No. It only reads. Use map.set, map.merge, or map.deep-merge when you need a new map with updates.
Did you know?
Official Sass docs highlight multi-key map.get because design systems often nest maps several levels deep. The same path style works with map.has-key, map.set, and the deep helpers like map.deep-merge.
map.get() is the everyday way to read Sass maps—flat or nested. Load it through sass:map, handle null with defaults or has-key, and use multi-key paths on Dart Sass 1.27+ for design-system trees.