Home Sass Meta meta.module-variables() Definition
Definition and Usage meta.module-variables($module) returns a map of every variable defined in $module—keys are names without $, values are the variable values. Dart Sass 1.23+ . Load with @use "sass:meta".
Official sample idea. After @use "variables" with $hopbush, $midnight-blue, and $wafer, meta.module-variables("variables") returns ("hopbush": #c69, …).
$module matches a namespace.Pass a string matching a @use namespace in the current file (e.g. "variables"), or a module value.
Keys omit $. Look up "hopbush", not "$hopbush", with map.get / map.has-key.
Syntax
Syntax @use "sass:map";
@use "sass:meta";
@use "variables";
meta.module-variables($module); //=> map
// Official tokens (keys without $)
$map: meta.module-variables("variables");
// ("hopbush": #c69, "midnight-blue": #036, "wafer": #e1d7d2)
color: map.get($map, "hopbush");
// Module API — Dart Sass 1.23+ Pattern: @use the module → module-variables for the catalog → map.get / map.has-key / @each.
Code
SCSS Examples Examples target Dart Sass 1.23+ with @use "sass:meta". Open View Compiled CSS for verified output (matches official Sass docs samples where shown).
1. Inspect 2. map.get 3. Probe 4. Theme 5. Guard Example 1 — Inspect the Official Variables Map Peek at the full map with meta.inspect (official hopbush / midnight-blue / wafer tokens).
$hopbush: #c69;
$midnight-blue: #036;
$wafer: #e1d7d2; @use "sass:meta";
@use "variables";
.probe {
--vars: #{meta.inspect(meta.module-variables("variables"))};
} .probe {
--vars: ("hopbush": #c69, "midnight-blue": #036, "wafer": #e1d7d2);
} How It Works @use "variables" loads the tokens.module-variables builds the map.Keys omit the $.Matches the official Sass docs sample shape.Example 2 — Use Tokens with map.get Read individual colors from the catalog into real CSS properties.
@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");
} .swatch {
color: #c69;
background: #e1d7d2;
border-color: #036;
} How It Works Store the map once in $vars.map.get pulls each token by string key.No $ in the key names.Values drop straight into CSS properties.Example 3 — Count and Probe Keys Combine map.keys, list.length, and map.has-key.
@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")};
} .probe {
--keys: "hopbush", "midnight-blue", "wafer";
--n: 3;
--has-hopbush: true;
--has-nope: false;
} How It Works Three tokens produce a count of 3.map.keys lists the bare names.has-key finds hopbush.Unknown names return false.Example 4 — Theme Spacing Module Same API for non-color tokens—radius, padding, and ink color.
$radius: 8px;
$pad: 1rem;
$ink: #123; @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");
} .card {
padding: 1rem;
border-radius: 8px;
color: #123;
} How It Works Any module variables work—not just colors.Namespace is "theme" from @use.map.get fills spacing and color.Handy for design-token / theme packs.Example 5 — Guard Before map.get Check map.has-key so optional token names fail safely.
@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;
} .box {
border-radius: 8px;
padding: 1rem;
} How It Works $name is looked up in the catalog.True path applies the theme radius.Missing names take the @else fallback.Safer for optional plugin tokens. Edge Cases & Pitfalls Most module-variables bugs are including $ in keys or mismatching the namespace.
keys No dollar sign in keys Pass "hopbush", not "$hopbush", to map.get.
namespace String must match @use After @use "variables" as tokens, pass "tokens", not "variables".
dart Dart Sass 1.23+ only Official docs: LibSass / Ruby Sass do not provide this API.
Toolchain
Sass Support Prefer the module form with Dart Sass 1.23+.
API Status meta.module-variables()Dart Sass 1.23+ via @use "sass:meta" Return type Map (bare name → value) $moduleNamespace string or module value LibSass / Ruby Sass Not available
Compile with the Dart Sass CLI .
Remember
Key Takeaways Returns a map of every variable in a loaded module.
Keys omit $ ; values are ready for CSS via map.get.
$module matches @use namespace in the current file.
Dart Sass 1.23+ — great for design-token catalogs.
One line: to list every variable in a @use module, use meta.module-variables($module).
Practice
Compile Notes Practical checklist:
1. @use "sass:meta" (+ "sass:map")
2. @use "your-module"
3. $vars: meta.module-variables("your-module")
4. map.get / map.has-key / map.keys (bare names)
5. Optional: @each $name, $value in $vars { … } Frequently Asked Questions What does Sass meta.module-variables() do? meta.module-variables($module) returns a map of every variable defined in that @use module—keys are names without $, values are the variable values.
What must $module be? A string matching the namespace of a @use rule in the current file—for example "variables" after @use "variables". It can also be a module value.
Do map keys include the dollar sign? No. Official docs: keys are variable names without $. So $hopbush becomes the key hopbush.
How is it different from meta.global-variable-exists? global-variable-exists answers yes/no for one global name. module-variables returns the whole catalog of variables in a module as a map.
How do I read one value from the map? Use map.get—for example map.get(meta.module-variables("variables"), "hopbush") returns #c69.
Which compilers support it? Dart Sass 1.23+. LibSass and Ruby Sass do not. Prefer current Dart Sass.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion