Sass meta.load-css() Function

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

What You’ll Learn

meta.load-css() belongs to the built-in sass:meta module. It loads another stylesheet module and includes only its CSS where you write the include—even nested under a selector. This page covers $with configuration, vs @use, nesting, dynamic URLs, Dart Sass 1.23+, and five examples.

01

Concept

Include module CSS

02

Module

@use "sass:meta"

03

Config

$with map

04

Nesting

Under selectors

05

vs @use

CSS only

06

Practice

5 examples

What Is meta.load-css()?

@use is the usual way to load a Sass module: you get its CSS and its members (variables, mixins, functions). Sometimes you only want the CSS, or you want that CSS nested under body.dark or a media query. Official docs: meta.load-css loads the module at $url and includes its CSS as though it were written as the contents of this mixin.

  • Use it with @include (it is a meta mixin)
  • Optional $with configures !default variables in the loaded file
  • Members from the loaded module are not available in the current file
  • Can appear anywhere—including nested inside style rules
💡
Beginner tip

Think of @use as borrowing a toolbox and hanging the posters on your wall. meta.load-css only hangs the posters—and you can hang them inside a room labeled body.dark.

📝 Syntax

Load the meta module, then include the mixin:

styles.scss
@use "sass:meta";

@include meta.load-css($url);
@include meta.load-css($url, $with: null);
@include meta.load-css($url, $with: ("var-name": value));

Parameters

ParameterTypeRequiredDescription
$urlStringYesModule URL like you would pass to @use (not a CSS url()). Relative paths are relative to the including file.
$withMap or nullNoOptional config map: keys are variable names without $; values configure those !default variables in the loaded module.
⚠️
Heads up (official docs)

$url must be a string URL for a Sass module—the same kind of string you give @use. Do not pass a CSS url(...) expression.

Return value

TypeResult
— (CSS output)Emits the loaded module’s CSS at the include site (nested if you nested the include). Does not return a Sass value.
⚠️
Mixin, not a returning function

Officially meta.load-css is a mixin in sass:meta. Always @include it—do not assign it like $x: meta.load-css(...).

📦 Loading sass:meta

There is no legacy global load-css(). Load the meta module and include meta.load-css.

styles.scss
// Recommended — namespaced
@use "sass:meta";
@include meta.load-css("components/button");

// Optional — bring members into scope
@use "sass:meta" as *;
@include load-css("components/button");

// Optional — custom namespace
@use "sass:meta" as m;
@include m.load-css("components/button");

📋 Like @use / Unlike @use

Official docs split the rules this way:

meta.load-css@use
Evaluates module onceYesYes
Can reconfigure after loadNoNo
Exposes membersNoYes (namespaced)
Where allowedAnywhere (even nested)Top of file (before most rules)
URL from a variableYesNo (static string)
Best forThemed / nested CSS inclusionSharing variables, mixins, functions

⚙️ Configuring with $with

Pass a map whose keys are variable names without the $ prefix. Those values configure matching !default variables in the loaded module.

styles.scss
@use "sass:meta";

// Loaded file has: $border-contrast: false !default;
@include meta.load-css(
  "dark-theme/code",
  $with: ("border-contrast": true)
);
⚠️
Already loaded?

You cannot provide configuration to a module that has already been loaded—whether or not it was loaded with configuration. Plan $with for the first load.

🛠 Compatibility

This is about Sass compilers, not browsers. The mixin runs at compile time; browsers only see the nested CSS it produces.

Implementationmeta.load-css()Notes
Dart Sass (1.23+)Yes — requiredOnly Dart Sass supports this mixin
LibSassNoNo modern sass:meta load-css API
Ruby SassNoLegacy—prefer Dart Sass

⚡ Quick Reference

GoalCode
Import meta@use "sass:meta";
Include module CSS@include meta.load-css("path/file");
Configure variables@include meta.load-css($url, $with: ("name": $val));
Nest under a selectorbody.dark { @include meta.load-css(...); }
Dynamic path@include meta.load-css("themes/#{$name}");
Need members too?Use @use instead (or as well, carefully)
Minimum Dart Sass1.23+

Examples Gallery

Examples show both the loaded partial and the including file (as in the official docs). Open View Compiled CSS for the finished output.

📚 Getting Started

Plain include and the official $with theme sample.

Example 1 — Include CSS from Another File

Load a partial’s CSS at the top level without importing its members.

styles.scss
// _button.scss
.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
}

// style.scss
@use "sass:meta";

@include meta.load-css("button");

How It Works

Dart Sass evaluates _button.scss and writes its CSS where the include sits. You cannot call mixins from button in style.scss unless you also @use that module.

Example 2 — Configure with $with (Official Docs)

Nest dark-theme code styles under body.dark and flip a !default flag.

styles.scss
// dark-theme/_code.scss
$border-contrast: false !default;

code {
  background-color: #6b717f;
  color: #d2e1dd;
  @if $border-contrast {
    border-color: #dadbdf;
  }
}

// style.scss
@use "sass:meta";

body.dark {
  @include meta.load-css(
    "dark-theme/code",
    $with: ("border-contrast": true)
  );
}

How It Works

$with: ("border-contrast": true) configures $border-contrast in the loaded module. Nesting under body.dark prefixes every selector from that file.

📈 Practical Patterns

Selector nesting, dynamic URLs, and media-query scopes.

Example 3 — Nest Under a Theme Class

Reuse one card partial for light and dark wrappers without duplicating rules by hand.

styles.scss
// _card.scss
.card {
  padding: 1rem;
  border-radius: 8px;
}

// style.scss
@use "sass:meta";

.theme-light {
  @include meta.load-css("card");
}

.theme-dark {
  @include meta.load-css("card");
}

How It Works

Each include nests the same CSS under a different parent. The module still evaluates once overall, but the CSS is emitted at each include site with the surrounding selectors.

Example 4 — URL from a Variable / Interpolation

Official docs: the module URL can come from a variable and include interpolation.

styles.scss
// themes/_ocean.scss
.banner { background: #0ea5e9; }

// style.scss
@use "sass:meta";

$theme: "ocean";

.hero {
  @include meta.load-css("themes/#{$theme}");
}

How It Works

"themes/#{$theme}" becomes "themes/ocean" at compile time. That flexibility is a major difference from a static @use string.

Example 5 — Nest Inside a Media Query

Scope a print stylesheet partial under @media print.

styles.scss
// _print.scss
a { color: #000; text-decoration: underline; }
nav { display: none; }

// style.scss
@use "sass:meta";

@media print {
  @include meta.load-css("print");
}

How It Works

Because meta.load-css can appear anywhere, wrapping it in @media print scopes every rule from the partial to print.

🚀 Real-World Use Cases

  • Theme wrappers — nest the same component CSS under .theme-dark / .theme-light.
  • Configurable partials — flip !default flags with $with (official dark-theme sample).
  • Dynamic theme paths — build the module URL from a variable or interpolation.
  • Media-scoped sheets — load print or reduced-motion CSS inside the matching query.
  • CSS-only composition — pull styles without exposing another file’s mixins into your namespace.

🧠 How Compilation Works

1

Write the include

Call @include meta.load-css($url, $with: ...) where the CSS should appear.

Source
2

Load & configure

Dart Sass loads the module (once) and applies $with to !default variables.

Compile
3

Nest if needed

Surrounding selectors or media queries wrap the emitted rules.

Nest
4

Plain CSS ships

Browsers never see meta.load-css—only the finished nested CSS.

⚠️ Common Pitfalls

  • Expecting members — variables/mixins from the loaded file are not available; use @use when you need them.
  • CSS url() as $url — pass a module string like "dark-theme/code", not url(...).
  • Reconfiguring a loaded module — first load wins; later $with cannot reconfigure it.
  • Forgetting !default$with configures defaulted variables; non-default variables may not accept overrides the same way.
  • Using it as a value — always @include; do not assign the mixin call.

💡 Best Practices

✅ Do

  • Use @use "sass:meta" and @include meta.load-css()
  • Pass module URLs as plain strings (like @use)
  • Use $with for theme flags on !default variables
  • Nest includes under theme classes or media queries when useful
  • Prefer Dart Sass 1.23+

❌ Don’t

  • Expect the browser to evaluate meta.load-css
  • Pass a CSS url() as $url
  • Assume you can call mixins from the loaded file afterward
  • Try to reconfigure a module that already loaded
  • Rely on LibSass / Ruby Sass for this API

Key Takeaways

Knowledge Unlocked

Five things to remember about meta.load-css()

Include module CSS anywhere—optional $with; no members; Dart Sass 1.23+.

5
Core concepts
📦 02

Module

sass:meta

@use
03

Config

$with map

Rule
04

vs @use

CSS only · nestable

Safe
05

Prefer

Dart Sass 1.23+

Tooling

❓ Frequently Asked Questions

meta.load-css($url, $with: null) loads the module at $url and includes its CSS as if that CSS were written where you include the mixin. It does not import variables, mixins, or functions into the current file.
@use loads a module and makes its members available (once, at the top). meta.load-css only pulls in CSS, can appear anywhere—even nested under a selector—and accepts a configurable $with map. It never exposes members.
An optional map from variable names (without $) to values. Those values configure !default variables in the loaded module, similar to @use "…" with (…).
The module is evaluated only once, like @use. You also cannot provide configuration to a module that was already loaded—configured or not.
It is a mixin from sass:meta. Always use @include meta.load-css(...). It emits CSS; it does not return a value.
Dart Sass 1.23+. LibSass and Ruby Sass do not provide this mixin. Prefer current Dart Sass.
Did you know?

The official dark-theme sample nests meta.load-css under body.dark so every selector from the loaded file becomes something like body.dark code—a clean way to scope a whole partial without rewriting it.

Conclusion

meta.load-css() is the CSS-only, nestable cousin of @use: include another module’s styles anywhere, optionally configure !default variables with $with, and keep its members out of your namespace. Load it through sass:meta on Dart Sass 1.23+.

Continue with meta.mixin-exists() or the Sass introduction.

Next: check if a mixin exists

Learn meta.mixin-exists() to guard optional mixin includes.

meta.mixin-exists() →

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