Sass meta.module-variables() Function

Intermediate
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:meta · Dart Sass 1.23+

What You’ll Learn

meta.module-variables() belongs to the built-in sass:meta module. It returns every variable in a @used module as a map of names (without $) to values. This page covers the official color-token example, map.get usage, and five compiled examples.

01

Concept

Module variable catalog

02

Module

@use "sass:meta"

03

Returns

Map of values

04

Keys

Names without $

05

Read path

map.get

06

Practice

5 examples

What Is meta.module-variables()?

Official docs: returns all the variables defined in a module, as a map from variable names (without $) to the values of those variables. Think of it as dumping a module’s token sheet into one map you can inspect, loop, or read with map.get.

  • $module must be a string matching a @use namespace in the current file.
  • Map keys omit $$hopbush becomes "hopbush".
  • Map values are the actual Sass values (colors, lengths, strings, and so on)—ready for CSS.
  • Dart Sass 1.23+ only—LibSass and Ruby Sass do not support it.
💡
Beginner tip

Unlike module-functions / module-mixins, you do not need meta.call or meta.apply. The map already holds usable values.

📝 Syntax

styles.scss
@use "sass:meta";

// Dart Sass 1.23+ (no legacy global name)
meta.module-variables($module)

Parameters

ParameterTypeRequiredDescription
$moduleStringYesMust match the namespace of a @use rule in the current file.

Return value

TypeResult
MapVariable names (no $) → variable values

📦 Loading sass:meta

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

$vars: meta.module-variables("variables");
$pink: map.get($vars, "hopbush"); // #c69

There is no legacy global module-variables(). Always load sass:meta and call meta.module-variables.

🎨 The Official Color Tokens Pattern

Docs load a variables partial and inspect the returned map:

styles.scss
// _variables.scss
$hopbush: #c69;
$midnight-blue: #036;
$wafer: #e1d7d2;

// styles.scss
@use "sass:meta";
@use "variables";

@debug meta.module-variables("variables");
// (
//   "hopbush": #c69,
//   "midnight-blue": #036,
//   "wafer": #e1d7d2
// )

If you wrote @use "variables" as tokens, pass "tokens" as $module.

📋 Related Meta Helpers

HelperPurposeReturns
meta.module-variablesAll variables in a moduleMap of values
meta.module-functionsAll functions in a moduleMap of function values
meta.module-mixinsAll mixins in a moduleMap of mixin values
meta.global-variable-existsDoes one global variable exist?Boolean
meta.variable-existsDoes a variable exist in the current scope?Boolean

🛠 Compatibility

This is about Sass compilers, not browsers. The map is built at compile time.

Implementationmodule-variables
Dart SassYes — since 1.23.0
LibSassNo
Ruby SassNo

Prefer current Dart Sass. Only Dart Sass supports this function.

⚡ Quick Reference

GoalCode
Import meta (+ map)@use "sass:meta"; @use "sass:map";
List a module’s variablesmeta.module-variables("variables")
See the namesmap.keys(meta.module-variables("theme"))
Read one valuemap.get($vars, "hopbush")
Guard a name@if map.has-key($vars, $name) { … }
Check one global insteadmeta.global-variable-exists("hopbush")

Examples Gallery

Each example uses meta.module-variables at compile time (Dart Sass 1.23+). Open View Compiled CSS for verified output.

📚 Getting Started

Official color tokens: inspect the map, then use map.get.

Example 1 — Inspect the Official Variables Map

Peek at the full map with meta.inspect (official hopbush / midnight-blue / wafer tokens).

styles.scss
$hopbush: #c69;
$midnight-blue: #036;
$wafer: #e1d7d2;
styles.scss
@use "sass:meta";
@use "variables";

.probe {
  --vars: #{meta.inspect(meta.module-variables("variables"))};
}

How It Works

Keys match the docs: names without $, values are the colors from the module.

Example 2 — Use Tokens with map.get

Read individual colors from the catalog into real CSS properties.

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

$vars: meta.module-variables("variables");

.swatch {
  color: map.get($vars, "hopbush");
  background: map.get($vars, "wafer");
  border-color: map.get($vars, "midnight-blue");
}

How It Works

Store the map once, then pull each token by its string key—no $ in the key.

📈 Practical Patterns

Inventory probes, theme modules, and safe optional tokens.

Example 3 — Count and Probe Keys

Combine map.keys, list.length, and map.has-key.

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

$vars: meta.module-variables("variables");

.probe {
  --keys: #{meta.inspect(map.keys($vars))};
  --n: #{list.length(map.keys($vars))};
  --has-hopbush: #{map.has-key($vars, "hopbush")};
  --has-nope: #{map.has-key($vars, "nope")};
}

How It Works

Three official tokens produce a count of 3. Missing names return false from has-key.

Example 4 — Theme Spacing Module

Same API for non-color tokens—radius, padding, and ink color.

styles.scss
$radius: 8px;
$pad: 1rem;
$ink: #123;
styles.scss
@use "sass:map";
@use "sass:meta";
@use "theme";

$theme: meta.module-variables("theme");

.card {
  padding: map.get($theme, "pad");
  border-radius: map.get($theme, "radius");
  color: map.get($theme, "ink");
}

How It Works

Any module variables work—not just colors. Useful for design-token files and theme packs.

Example 5 — Guard Before map.get

Check map.has-key so optional token names fail safely.

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

$theme: meta.module-variables("theme");
$name: "radius";

.box {
  @if map.has-key($theme, $name) {
    border-radius: map.get($theme, $name);
  } @else {
    border-radius: 0;
  }
  padding: 1rem;
}

How It Works

When $name is present, the theme radius is applied. If it were missing, the @else branch would keep a safe fallback.

🚀 Real-World Use Cases

  • Design-token dumps — load a colors or spacing module and read tokens by name.
  • Theme packs — swap which module you @use, then rebuild styles from its map.
  • Documentation / debug peeks — print keys or the full map with meta.inspect.
  • Safe optional tokensmap.has-key before map.get.
  • Code generation — loop @each $name, $value in … to emit CSS custom properties.

🧠 How Compilation Works

1

@use a variables module

Load variables, theme, or another namespace.

Source
2

Build the variables map

Call meta.module-variables("variables").

Compile
3

Read with map.get

Use keys without $, or loop with @each.

Use
4

CSS ships

Browsers never see the map—only finished colors and lengths.

⚠️ Common Pitfalls

  • Including $ in keys — look up "hopbush", not "$hopbush".
  • Wrong namespace string — must match this file’s @use … as name exactly.
  • Module not loaded here — only @use rules in the current file count.
  • Confusing with function/mixin maps — these values are ready to use; no meta.call / apply.
  • Expecting LibSass — this API is Dart Sass only (1.23+).

💡 Best Practices

✅ Do

  • Use @use "sass:meta" and meta.module-variables()
  • Store the map once when reading several tokens
  • Guard optional names with map.has-key
  • Remember keys omit $
  • Run Dart Sass 1.23+

❌ Don’t

  • Pass a path string that is not a current-file @use namespace
  • Look up keys with a leading $
  • Use it to list functions or mixins (use the sibling helpers)
  • Assume browsers evaluate the lookup
  • Rely on LibSass / Ruby Sass

Key Takeaways

Knowledge Unlocked

Five things to remember about meta.module-variables()

Get every variable in a @use module as a map, then read values with map.get.

5
Core concepts
📦 02

Module

sass:meta

@use
📚 03

Returns

map of values

Result
🔗 04

Keys

names without $

Detail
05

Read

map.get($vars, name)

Tooling

❓ Frequently Asked Questions

meta.module-variables($module) returns a map of every variable defined in that @use module—keys are names without $, values are the variable values.
A string matching the namespace of a @use rule in the current file—for example "variables" after @use "variables".
No. Official docs: keys are variable names without $. So $hopbush becomes the key hopbush.
global-variable-exists answers yes/no for one global name. module-variables returns the whole catalog of variables in a module as a map.
Use map.get—for example map.get(meta.module-variables("variables"), "hopbush") returns #c69.
Dart Sass 1.23+. LibSass and Ruby Sass do not. Prefer current Dart Sass.
Did you know?

Official Sass docs use playful color names—hopbush, midnight-blue, and wafer—to show that module-variables returns a plain map of tokens you can treat like any other Sass map.

Conclusion

meta.module-variables() returns a map of every variable in a @used module. Match $module to that namespace, remember keys omit $, and read tokens with map.get on Dart Sass 1.23+.

Continue with meta.type-of() or the Sass introduction.

Next: detect a value’s type

Learn meta.type-of() to branch on number, list, map, and more.

meta.type-of() →

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