Sass Module Values

Intermediate
11 min read
Updated: Nov 2026
5 examples
Dart Sass 1.105+

Definition and Usage

A module is a Sass stylesheet that has been loaded—by @use or as a built-in such as sass:math. It holds variables, functions, mixins, and CSS. With first-class modules a loaded module can also be a value you keep in a variable and pass around.

You get a module value two ways: meta.load() loads a stylesheet by URL, and meta.get-module() fetches one you already loaded with @use by its namespace.

Loading is not including.

meta.load() evaluates a stylesheet but emits no CSS by itself. Emit its CSS on purpose with @include meta.css($module), or use the shorthand meta.load-css().

Pass it to existing helpers.

A module value can be given as the $module argument of meta.get-function(), meta.get-mixin(), meta.module-variables(), meta.module-functions(), and meta.module-mixins().

Loaded once.

A module is evaluated only once. You cannot configure it with $with after it was already loaded, and meta.css() can emit its CSS each time you include it.

Does Sass have “hooks”?

No. Official Sass has no hooks API (nothing like theme hook files or lifecycle callbacks). When people say “hooks” for Sass they usually mean these customization points instead:

  • !default variables — a library exposes knobs; consumers override them before or while loading the module.
  • @use "lib" with ($primary: …) — configure those knobs the first time a module loads.
  • meta.load($url, $with: (...)) — the same configuration idea when you load a module as a value.
  • @forward + @use — re-export and compose library entrypoints without global pollution.
  • First-class mixins / functions — pass behavior around with meta.get-mixin(), meta.apply(), meta.get-function(), and meta.call().

Those five tools cover sharing, configuring, and swapping behavior. There is no separate hooks feature to learn beyond them.

Syntax

SCSS
@use "sass:meta";
@use "theme";                          // namespace: theme

$a: meta.get-module("theme");          // already-loaded module
$b: meta.load("theme");                // load by URL (no CSS yet)
$c: meta.load("theme", $with: ("primary": #c6538c));

@include meta.css($b);                 // emit its CSS here
@include meta.load-css("theme");       // shorthand: load + emit

meta.module-variables($a);             // map of variables
meta.get-function("rem", $module: $a); // function from the module

Pattern: load or fetch a module → inspect or use its members → emit its CSS only where you want it.

Working with Module Values

Which tool to reach for:

GoalToolNotes
Get a module already loadedmeta.get-module("namespace")Uses the @use namespace
Load a stylesheet as a valuemeta.load($url, $with)Does not emit CSS
Emit a module’s CSS@include meta.css($module)Can appear anywhere, even nested
Load and emit in one step@include meta.load-css($url)Same output as css + load
List membersmeta.module-variables / -functions / -mixinsAccept a module value
Reach one membermeta.get-function(..., $module:) / get-mixinAccept a module value
No hooks feature.

Sass has no separate “hooks” system. Modules, @use configuration (with), and these meta functions are how stylesheets share and customise behavior.

SCSS Examples

Examples target Dart Sass 1.105+. Helper files are shown above each main file. Open View Compiled CSS to see the result.

Example 1 — Fetch a Loaded Module

Turn the theme namespace into a module value.

SCSS
$primary: #036 !default;
$radius: 4px !default;

.theme {
  color: $primary;
}
SCSS
@use "sass:meta";
@use "theme";

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

.info {
  --type: #{meta.type-of($module)};
  --inspect: #{meta.inspect($module)};
  --primary: #{theme.$primary};
}

How It Works

  1. @use "theme" loads the file; its CSS is emitted once at the top.
  2. meta.get-module("theme") fetches the loaded module by namespace.
  3. meta.type-of reports module; meta.inspect prints get-module("theme").
  4. Members are still read with theme.$primary.

Example 2 — Load a Module Without Emitting CSS

meta.load() evaluates the file but leaves its CSS out.

SCSS
$primary: #036 !default;
$radius: 4px !default;

.theme {
  color: $primary;
}
SCSS
@use "sass:map";
@use "sass:meta";

$theme: meta.load("theme");

.info {
  --type: #{meta.type-of($theme)};
  --primary: #{map.get(meta.module-variables($theme), "primary")};
  --radius: #{map.get(meta.module-variables($theme), "radius")};
}

How It Works

  1. meta.load("theme") loads the stylesheet as a module value.
  2. No .theme rule appears—loading alone emits no CSS.
  3. meta.module-variables($theme) returns its variables as a map.
  4. map.get reads individual values.

Example 3 — Configure with $with, Then Emit with meta.css

Override !default variables when you first load a module.

SCSS
$primary: #036 !default;
$radius: 4px !default;

.theme {
  color: $primary;
}
SCSS
@use "sass:meta";

$theme: meta.load("theme", $with: ("primary": #c6538c));

@include meta.css($theme);

How It Works

  1. $with maps variable names (without $) to new values.
  2. Only !default variables can be configured.
  3. @include meta.css($theme) emits the module’s CSS using the configured colour.
  4. Configure once—a module that was already loaded cannot be reconfigured.

Example 4 — Use a Module Value with get-function and get-mixin

Pass the module as $module instead of a namespace string.

SCSS
@use "sass:math";

@function rem($px) {
  @return math.div($px, 16px) * 1rem;
}

@mixin stretch {
  display: flex;
  flex: 1;
}
SCSS
@use "sass:meta";

$theme: meta.load("theme");

.header {
  @include meta.apply(meta.get-mixin("stretch", $module: $theme));
  font-size: meta.call(meta.get-function("rem", $module: $theme), 24px);
}

How It Works

  1. meta.load("theme") gives a module value with no namespace needed.
  2. $module: $theme points get-mixin and get-function at it.
  3. meta.apply includes the stretch mixin.
  4. meta.call runs rem(24px) and returns 1.5rem.

Example 5 — meta.css vs meta.load-css

Emit a module’s CSS under a selector two equivalent ways.

SCSS
$primary: #036 !default;

.theme {
  color: $primary;
}
SCSS
@use "sass:meta";

.scope-a {
  @include meta.css(meta.load("theme"));
}

.scope-b {
  @include meta.load-css("theme");
}

How It Works

  1. meta.css(meta.load(...)) loads, then emits the CSS in place.
  2. meta.load-css(...) is the shorthand for the same two steps.
  3. Both nest the module’s CSS under the surrounding selector.
  4. The module is evaluated once, so variables are shared.

Edge Cases & Pitfalls

Most module-value issues are namespace names, loading order, and expecting CSS from a plain load.

namespace

get-module needs the namespace

meta.get-module("theme") works only for modules loaded with @use in the current file. Use the alias if you wrote @use "theme" as t, and not the full URL.

css

Loading alone emits no CSS

meta.load() evaluates the stylesheet. Add @include meta.css($module) (or use meta.load-css()) to output its CSS.

with

Configure before the first load

A module that was already loaded—with or without configuration—cannot be loaded again with $with. The compiler reports it.

dup

Each meta.css repeats the CSS

@use emits a module’s CSS once. Every @include meta.css($m) emits it again where you put it.

Sass Support

First-class modules arrived in a recent Dart Sass release.

FeatureStatus
meta.load(), meta.get-module(), meta.css()Dart Sass 1.105+
meta.load-css()Dart Sass 1.23+
$module accepting a module valueDart Sass 1.105+
LibSass / Ruby SassNot supported

Compile with the Dart Sass CLI.

Key Takeaways

  • A module is a loaded stylesheet with variables, functions, mixins, and CSS.
  • meta.load() and meta.get-module() give you a module as a value.
  • Loading emits no CSS—use meta.css() or meta.load-css() to output it.
  • Module values plug into the existing meta functions via $module.

One line: load or fetch a module as a value, inspect its members, and emit its CSS only where you want it.

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. meta.get-module("namespace") for a @use'd module
3. meta.load("url", $with: (...)) to load by URL
4. @include meta.css($module) to emit its CSS
5. Pass the module as $module to get-function / get-mixin

Frequently Asked Questions

A module value is a first-class reference to a loaded stylesheet. It holds variables, functions, mixins, and CSS, and can be stored in a variable or passed to meta functions.
Use meta.get-module("namespace") for a module already loaded with @use, or meta.load("url") to load a stylesheet by URL.
No. It only evaluates the stylesheet. Use @include meta.css($module) to emit its CSS, or meta.load-css() to load and emit in one step.
Yes, with the $with map, for example meta.load("theme", $with: ("primary": #c6538c)). Only !default variables can be configured, and a module already loaded cannot be reconfigured.
Pass it as the $module argument of meta.get-function(), meta.get-mixin(), meta.module-variables(), meta.module-functions(), or meta.module-mixins().
No. Sass has no separate hooks feature. Modules, @use with configuration, and the meta module functions are how stylesheets share and customise behavior.

Next: Sass Equality Operators

Compare values with == and != in Sass.

Equality Operators →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

8 people found this page helpful