map.remove() belongs to the built-in sass:map module. It returns a new map with one or more top-level keys deleted. This page covers multi-key removal, missing keys, immutability, vs map.deep-remove, the legacy map-remove name, and five compiled examples.
01
Concept
Delete top-level keys
02
Module
@use "sass:map"
03
Many keys
One call, several removals
04
Missing
Ignored safely
05
vs deep-remove
Top-level vs nested path
06
Practice
5 examples
Concept
What Is map.remove()?
Design token maps grow over time. Sometimes you need a copy without a legacy flag, a deprecated color, or a weight you no longer ship. map.remove() does exactly that for top-level keys:
Pass the map, then every key you want gone
Get a new map back—the original stays unchanged
Keys that were never there are simply ignored
It does not walk into nested maps. To delete fonts → Helvetica → weights → regular, use map.deep-remove().
💡
Beginner tip
Think of a flat folder of files. map.remove deletes whole files at the root. It cannot open a subfolder and delete one file inside—that is map.deep-remove.
Foundation
📝 Syntax
Load the map module, then call the function:
styles.scss
@use "sass:map";
map.remove($map, $keys...)
Parameters
Parameter
Type
Required
Description
$map
Map
Yes
Source map. Never mutated—you always get a new map back.
$keys...
Any (variadic)
Yes*
One or more top-level keys to drop. Missing keys are ignored.
*You normally pass at least one key. Passing none returns a copy of the map unchanged.
Return value
Type
Situation
Result
Map
Key(s) exist
New map without those top-level entries
Map
Key missing
That key is skipped; other removals still apply
Map
All keys missing
Copy of $map (same keys and values)
Modules
📦 Loading sass:map
Modern Sass groups map helpers into a module. Load it with @use, then call map.remove. The older global name map-remove still works.
styles.scss
// Recommended — namespaced
@use "sass:map";
$clean: map.remove($tokens, "legacy");
// Optional — bring members into the current namespace
@use "sass:map" as *;
$clean: remove($tokens, "legacy");
// Optional — custom namespace
@use "sass:map" as m;
$clean: m.remove($tokens, "legacy");
// Legacy global
$clean: map-remove($tokens, "legacy");
⚠️
Put @use first
@use rules must appear before most other rules. Keep @use "sass:map"; near the top of the file.
Both return a new map without certain keys. The difference is depth.
map.remove
map.deep-remove
Target
Top-level keys only
Top-level or nested leaf via path
Extra arguments
More keys to delete at the root
Path keys; last key is removed
Best for
Flat token maps
Nested theme / config trees
Legacy global
map-remove
None—module only
Since (deep path)
Long-standing
Dart Sass 1.27+
💡
Quick pick
Flat map like ("primary": …, "muted": …)? Use map.remove. Nested path like ("colors": ("accent": …)) and you only want accent gone? Use map.deep-remove.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS only contains the finished values you read from the cleaned map (for example with map.get).
Implementation
@use "sass:map"
Global map-remove
Dart Sass (1.23+)
Yes — preferred
Yes
LibSass
No built-in modules
Yes (legacy)
Ruby Sass
No built-in modules
Yes (legacy)
Prefer Dart Sass for new work. Use map.deep-remove on Dart Sass 1.27+ when you need nested key paths.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import map
@use "sass:map";
Remove one key
map.remove($map, "legacy")
Remove several keys
map.remove($map, "a", "b")
Nested leaf key
map.deep-remove($map, "a", "b", "leaf")
Keep result
$map: map.remove($map, "temp");
Legacy global call
map-remove($map, "legacy")
Hands-On
Examples Gallery
Each example uses @use "sass:map". Open View Compiled CSS to see what Dart Sass emits (maps inspected via meta.inspect where needed).
📚 Getting Started
Official docs samples: one key, many keys, missing keys.
Legacy cleanup — drop deprecated tokens from a shared palette map.
Feature subsets — build a lighter token map for a component package.
Safe optional deletes — list keys that might not exist; missing ones are ignored.
Flat maps only — pair with map.deep-remove when nesting is involved.
🧠 How Compilation Works
1
Write SCSS
Call map.remove($map, $key, …) after @use "sass:map".
Source
2
Keys are filtered
Dart Sass copies the map and drops each listed top-level key that exists.
Compile
3
New map returned
Read remaining tokens with map.get or loop with map.keys.
Result
4
✓
CSS sees values
Browsers never see map.remove—only the finished CSS you emit.
Watch Out
⚠️ Common Pitfalls
Expecting nested deletes — map.remove($map, "colors", "accent") treats both as top-level keys to delete, not a path. Use map.deep-remove for paths.
Forgetting to reassign — remove returns a copy; originals stay unless you assign the result.
Deleting a whole branch by mistake — removing a nested map’s parent key drops every child token.
Assuming missing keys error — they are ignored; double-check spellings if nothing changed.
Forgetting @use — map.remove needs sass:map (or use legacy map-remove).
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:map" and map.remove() in new SCSS
Pass every top-level key you want gone in one call
Choose map.deep-remove for nested leaf keys
Reassign when updating a stored config variable
Prefer Dart Sass for the module API
❌ Don’t
Expect the browser to evaluate map.remove
Treat extra arguments as a nested path (that is deep-remove)
Assume originals mutate without reassignment
Remove a parent key when you only meant to drop one child
Rely on errors to catch typos—missing keys are silent
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about map.remove()
Top-level key deletion—returns a new map; missing keys ignored.
5
Core concepts
📝01
Call
map.remove($map, $keys...)
API
📦02
Module
sass:map
@use
🗑03
Scope
top-level only
Rule
❓04
Missing keys
ignored safely
Safe
✓05
Legacy
map-remove still works
Tooling
❓ Frequently Asked Questions
map.remove($map, $keys...) returns a new map without the listed top-level keys. Other keys stay in place. It does not dig into nested maps—use map.deep-remove for nested paths.
No. It returns a copy. Reassign if you need to keep the result: $tokens: map.remove($tokens, "legacy").
Missing keys are ignored. The result is still a valid copy of the map (unchanged for those keys). No error is thrown.
Yes. Pass every key after the map: map.remove($map, "a", "b", "c").
Yes. map-remove($map, $keys...) is the older global name. Prefer map.remove after @use "sass:map".
map.remove only deletes top-level keys. map.deep-remove can walk a nested path and delete a leaf key while keeping parent maps and siblings.
Did you know?
Official Sass docs show three map.remove calls on the same font-weight map: remove one key, remove two keys, and remove a missing key. That third case is intentional—it teaches that unknown keys are ignored instead of throwing.
map.remove() is the simple way to drop top-level keys from a Sass map: list the keys, get a new map back, and ignore any names that were never there. Use it for flat token cleanup; switch to map.deep-remove when you need a nested path.