Sass map.values() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:map · Dart Sass

What You’ll Learn

map.values() belongs to the built-in sass:map module. It returns a comma-separated list of every value in a map. This page covers order, nested map values, vs map.keys, the legacy map-values name, looping patterns, and five compiled examples.

01

Concept

List all values

02

Module

@use "sass:map"

03

Result

Comma-separated list

04

vs keys

Values vs names

05

Loops

@each patterns

06

Practice

5 examples

What Is map.values()?

Maps store named pairs like "medium": 500. Sometimes you only need the data—the numbers, colors, or lengths—not the names. Official docs: map.values returns a comma-separated list of all values in $map.

  • Order matches the map’s key order
  • Only top-level values of the map you pass (nested maps appear as whole items)
  • Result is a list—use list.length, list.nth, or @each
💡
Beginner tip

Think of a table of contents: map.keys lists the chapter titles. map.values lists the page numbers. map.get opens one chapter.

📝 Syntax

Load the map module, then call the function:

styles.scss
@use "sass:map";

map.values($map)

// Legacy global name (still works)
map-values($map)

Parameters

ParameterTypeRequiredDescription
$mapMapYesMap whose values you want. Not modified.

Return value

TypeResult
ListComma-separated list of all values, in map order (empty list for an empty map)

📦 Loading sass:map

Modern Sass groups map helpers into a module. Load it with @use, then call map.values. The older global name map-values still works.

styles.scss
// Recommended — namespaced
@use "sass:map";
$nums: map.values($theme);

// Optional — bring members into scope
@use "sass:map" as *;
$nums: values($theme);

// Optional — custom namespace
@use "sass:map" as m;
$nums: m.values($theme);

// Legacy global
$nums: map-values($theme);
⚠️
Put @use first

@use rules must appear before most other rules. Keep @use "sass:map"; near the top of the file.

🔢 Order & Nested Values

Two rules beginners should remember:

  • Order — values follow the same order as keys in the map
  • Nesting — if a value is itself a map, that whole map is one list item (no automatic flatten)
styles.scss
@use "sass:map";

$flat: ("regular": 400, "medium": 500, "bold": 700);
map.values($flat);
// 400, 500, 700

$nested: ("weights": ("regular": 400), "family": "Helvetica");
map.values($nested);
// ("regular": 400), "Helvetica"  — first item is still a map

📋 map.values vs map.keys

map.valuesmap.keys
ReturnsStored valuesKey names
OrderSame as map key orderSame as map key order
Best forEmit numbers/colors; math over tokensClass names; lookups with map.get
Legacy globalmap-valuesmap-keys
💡
Need both key and value?

Prefer @each $key, $value in $map { ... }. That walks the map directly without calling map.keys or map.values.

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS only contains the finished values you emit from the list (for example colors or lengths).

Implementation@use "sass:map"Global map-values
Dart Sass (1.23+)Yes — preferredYes
LibSassNo built-in modulesYes (legacy)
Ruby SassNo built-in modulesYes (legacy)

Prefer Dart Sass for new work and the module API.

⚡ Quick Reference

GoalCode
Import map@use "sass:map";
List valuesmap.values($map)
List keysmap.keys($map)
Count entrieslist.length(map.values($map))
Loop values only@each $v in map.values($map) { ... }
Nested map’s valuesmap.values(map.get($map, "colors"))
Legacy global callmap-values($map)

Examples Gallery

Each example uses @use "sass:map". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official docs sample and looping over values.

Example 1 — List Font Weights (Official Docs)

Turn a weight map into a comma-separated list of numbers.

styles.scss
@use "sass:map";
@use "sass:meta";

$font-weights: ("regular": 400, "medium": 500, "bold": 700);

@debug map.values($font-weights); // 400, 500, 700

.weights {
  --values: #{meta.inspect(map.values($font-weights))};
}

How It Works

Keys are discarded for this call. Only the three numeric values remain, in map order.

Example 2 — Loop Values with @each

Emit utility classes from a spacing scale without caring about key names.

styles.scss
@use "sass:map";
@use "sass:list";

$space: (
  "sm": 0.5rem,
  "md": 1rem,
  "lg": 1.5rem
);

@each $size in map.values($space) {
  $i: list.index(map.values($space), $size);
  .pad-#{$i} {
    padding: $size;
  }
}

How It Works

@each walks the value list. list.index gives a simple numeric suffix for class names. Prefer key-based names when the token name matters more.

📈 Practical Patterns

Palettes, nested maps, and counting entries.

Example 3 — Emit Palette Colors

Use each color value as a CSS custom property index.

styles.scss
@use "sass:map";
@use "sass:list";

$palette: (
  "primary": #1d4ed8,
  "accent": #e67e22,
  "muted": #94a3b8
);
$colors: map.values($palette);

:root {
  --c1: #{list.nth($colors, 1)};
  --c2: #{list.nth($colors, 2)};
  --c3: #{list.nth($colors, 3)};
}

How It Works

map.values produces a list; list.nth picks each color by position. For named variables like --primary, loop keys instead.

Example 4 — Values of a Nested Map

First map.get the nested branch, then list its values.

styles.scss
@use "sass:map";
@use "sass:meta";

$theme: (
  "colors": (
    "primary": #1d4ed8,
    "accent": #e67e22
  ),
  "radius": 8px
);

$color-values: map.values(map.get($theme, "colors"));

.demo {
  --nested-values: #{meta.inspect($color-values)};
  --top-values: #{meta.inspect(map.values($theme))};
}

How It Works

Top-level map.values($theme) keeps the colors map as one item. Digging into "colors" first gives a flat list of color values.

Example 5 — Count Map Entries

list.length(map.values($map)) equals the number of top-level keys.

styles.scss
@use "sass:map";
@use "sass:list";

$tokens: (
  "primary": #1d4ed8,
  "radius": 8px,
  "gap": 16px
);

.count {
  --entries: #{list.length(map.values($tokens))};
}

How It Works

Three values means three top-level entries. list.length(map.keys($tokens)) would return the same count.

🚀 Real-World Use Cases

  • Token dumps — emit every spacing or color value without building class names from keys.
  • Indexed utilities — generate .pad-1, .pad-2 style classes from value order.
  • List math — pass map values into list helpers when only magnitudes matter.
  • Nested branch exportmap.values(map.get(...)) for one config subtree.
  • Quick counts — measure how many top-level tokens a map holds.

🧠 How Compilation Works

1

Write SCSS

Call map.values($map) after @use "sass:map".

Source
2

Collect values

Dart Sass walks the map in key order and builds a list of values.

Compile
3

List returned

Loop with @each, index with list.nth, or count with list.length.

Result
4

CSS sees values

Browsers never see map.values—only the finished CSS you emit.

⚠️ Common Pitfalls

  • Expecting deep flatten — nested maps stay as map items in the list until you dig in with map.get.
  • Losing key names — values alone cannot rebuild which token was which; keep keys when names matter.
  • Order assumptions — order matches the map, but maps built from merges may append new keys at the end.
  • Forgetting @usemap.values needs sass:map (or use legacy map-values).
  • Using values when you need pairs — prefer @each $key, $value in $map for named output.

💡 Best Practices

✅ Do

  • Use @use "sass:map" and map.values() in new SCSS
  • Use values when only the data matters (not the names)
  • Call map.values(map.get(...)) for a nested branch
  • Pair with list.length / list.nth as needed
  • Prefer Dart Sass for the module API

❌ Don’t

  • Expect the browser to evaluate map.values
  • Assume nested maps are flattened automatically
  • Drop keys when you still need them for class names
  • Rely on LibSass for @use "sass:map"
  • Skip @each $key, $value when both sides are required

Key Takeaways

Knowledge Unlocked

Five things to remember about map.values()

Comma-separated value list—same order as keys; top-level only.

5
Core concepts
📦 02

Module

sass:map

@use
🔢 03

Returns

comma-separated list

Rule
04

vs keys

data vs names

Safe
05

Legacy

map-values still works

Tooling

❓ Frequently Asked Questions

map.values($map) returns a comma-separated list of all values in the map, in the same order as the map’s keys. It does not flatten nested maps—nested map values appear as map items in the list.
map.keys returns the names (keys). map.values returns the stored values in the same order. Use keys when you need names; use values when you only need the numbers, colors, or other data.
Yes. map-values($map) is the older global name. Prefer map.values after @use "sass:map".
No automatic deep flatten. map.values only lists values of the map you pass. To list values inside a nested map, first get that nested map: map.values(map.get($theme, "colors")).
map.values(()) returns an empty list (). list.length of that list is 0.
Use @each $value in map.values($map) { ... }. If you also need the key name, prefer @each $key, $value in $map or loop map.keys and call map.get.
Did you know?

Official Sass docs place map.values next to map.keys as a matching pair: one lists names, the other lists stored data—both as comma-separated lists in the same map order.

Conclusion

map.values() turns a Sass map into a list of its stored data—ideal for loops, indexed utilities, and list helpers when names do not matter. Load it through sass:map, dig into nested branches with map.get first when needed, and pair it with map.keys when you need both sides of each token.

Continue with meta.accepts-content() or the Sass introduction.

Next: check mixin content support

Learn meta.accepts-content() before forwarding @content dynamically.

meta.accepts-content() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful