Sass meta.apply() Function

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

What You’ll Learn

meta.apply() belongs to the built-in sass:meta module. It includes a mixin value with arguments you supply—like calling a mixin when you only have a reference to it. This page covers meta.get-mixin, @content forwarding, vs meta.call, Dart Sass 1.69+, and five compiled examples.

01

Concept

Dynamic mixin include

02

Module

@use "sass:meta"

03

How

@include meta.apply

04

Source

meta.get-mixin

05

vs call

Mixin vs function

06

Practice

5 examples

What Is meta.apply()?

Normally you write @include font-class(12px) with the mixin name fixed in the stylesheet. Sometimes you want to choose which mixin to run—pass it into another mixin, store it, or pick it from a map. Sass represents that choice as a mixin value. meta.apply includes that value with arguments.

  • You use it with @include (it is a meta mixin, not a returning function)
  • $mixin must be a mixin value—usually from meta.get-mixin("name")
  • Extra arguments after the mixin are forwarded as the mixin’s parameters
  • An optional @content block is forwarded into the applied mixin
💡
Beginner tip

Think of meta.get-mixin as picking a tool from a toolbox, and meta.apply as using that tool with the settings you pass. meta.call is the same idea for functions that return values.

📝 Syntax

Load the meta module, then include the mixin:

styles.scss
@use "sass:meta";

@include meta.apply($mixin, $args...);

// With a content block (forwarded to $mixin)
@include meta.apply($mixin, $args...) {
  // @content for the applied mixin
}

Parameters

ParameterTypeRequiredDescription
$mixinMixin valueYesMixin to include. Get one with meta.get-mixin($name) (or from meta.module-mixins).
$args...Any (variadic)NoArguments passed through to the applied mixin’s parameters.

Return value

TypeResult
— (CSS output)Emits whatever the applied mixin emits. Does not return a Sass value.
⚠️
Mixin, not a returning function

Despite the tutorial title pattern used across CodeToFun, meta.apply is documented as a mixin in sass:meta. Always @include it—do not assign it like $x: meta.apply(...).

📦 Loading sass:meta

There is no legacy global apply(). Load the meta module and include meta.apply.

styles.scss
// Recommended — namespaced
@use "sass:meta";
@include meta.apply(meta.get-mixin("font-class"), 12px);

// Optional — bring members into scope
@use "sass:meta" as *;
@include apply(get-mixin("font-class"), 12px);

// Optional — custom namespace
@use "sass:meta" as m;
@include m.apply(m.get-mixin("font-class"), 12px);
⚠️
Put @use first

Keep @use "sass:meta"; near the top of the file, before most other rules.

🔗 Pair with meta.get-mixin

meta.apply does not accept a string mixin name by itself. First resolve the mixin value:

styles.scss
@use "sass:meta";

@mixin alert($msg) {
  .alert { content: "#{$msg}"; }
}

// Resolve → include
$m: meta.get-mixin("alert");
@include meta.apply($m, "Saved");

// Or inline
@include meta.apply(meta.get-mixin("alert"), "Saved");
  • meta.get-mixin($name) — mixin in the current module
  • meta.get-mixin($name, $module) — mixin from a @use namespace
  • By default, a missing name is an error

📋 meta.apply vs meta.call

meta.applymeta.call
RunsMixin valuesFunction values
How you invoke@include meta.apply(...)meta.call(...) (expression)
Typical gettermeta.get-mixinmeta.get-function
OutputCSS / side effects from the mixinA returned Sass value
@contentCan forward a content blockN/A
SinceDart Sass 1.69+Longer-standing (module since 1.23+)

🛠 Compatibility

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

Implementationmeta.apply()Notes
Dart Sass (1.69+)Yes — requiredMixin values + meta.apply landed in 1.69.0
LibSassNoNo modern sass:meta apply API
Ruby SassNoLegacy—prefer Dart Sass

Prefer current Dart Sass. Built-in modules need Dart Sass 1.23+; meta.apply specifically needs 1.69+.

⚡ Quick Reference

GoalCode
Import meta@use "sass:meta";
Get a mixin valuemeta.get-mixin("name")
Include it@include meta.apply($m, $arg1, $arg2);
With content@include meta.apply($m) { ... }
Apply to each list item@include meta.apply($m, $item); inside @each
Run a function insteadmeta.call(meta.get-function("name"), $args...)
Minimum Dart Sass1.69+

Examples Gallery

Each example uses @use "sass:meta". Open View Compiled CSS for verified Dart Sass output (official samples where noted).

📚 Getting Started

Resolve a mixin, then include it—alone and across a list.

Example 1 — Basic get-mixin + apply

Store a mixin value, then include it once with an argument.

styles.scss
@use "sass:meta";

@mixin badge($label) {
  .badge {
    content: "#{$label}";
  }
}

$badge-mixin: meta.get-mixin("badge");
@include meta.apply($badge-mixin, "New");

How It Works

meta.get-mixin("badge") returns a mixin value. meta.apply includes it as if you wrote @include badge("New").

Example 2 — Apply to All (Official Docs)

Pass each list item to a separate invocation of the same mixin.

styles.scss
@use "sass:meta";

/// Passes each element of $list to a separate invocation of $mixin.
@mixin apply-to-all($mixin, $list) {
  @each $element in $list {
    @include meta.apply($mixin, $element);
  }
}

@mixin font-class($size) {
  .font-#{$size} {
    font-size: $size;
  }
}

$sizes: 8px, 12px, 2rem;

@include apply-to-all(meta.get-mixin("font-class"), $sizes);

How It Works

apply-to-all never hard-codes font-class. It receives any mixin value and reuses the same loop for every list item—the pattern from the official docs.

📈 Practical Patterns

Multiple args, content blocks, and choosing a mixin at compile time.

Example 3 — Multiple Arguments

Every argument after the mixin value is forwarded in order.

styles.scss
@use "sass:meta";

@mixin shadow-box($x, $y, $blur) {
  .card {
    box-shadow: $x $y $blur rgba(0, 0, 0, 0.2);
  }
}

@include meta.apply(meta.get-mixin("shadow-box"), 0, 4px, 12px);

How It Works

0, 4px, and 12px map to $x, $y, and $blur on shadow-box.

Example 4 — Forward a @content Block

Content passed to meta.apply is forwarded into the applied mixin.

styles.scss
@use "sass:meta";

@mixin panel($radius) {
  .panel {
    border-radius: $radius;
    @content;
  }
}

@include meta.apply(meta.get-mixin("panel"), 8px) {
  padding: 1rem;
  background: #f8fafc;
}

How It Works

Official behavior: if meta.apply receives a content block, that block is forwarded to $mixin. Here it lands where panel writes @content.

Example 5 — Choose a Mixin Dynamically

Pick which mixin value to apply based on a flag or config token.

styles.scss
@use "sass:meta";

@mixin solid-btn {
  .btn { background: #1d4ed8; color: #fff; }
}

@mixin outline-btn {
  .btn { background: transparent; border: 2px solid #1d4ed8; }
}

$variant: "outline";
$mixin: if(
  $variant == "outline",
  meta.get-mixin("outline-btn"),
  meta.get-mixin("solid-btn")
);

@include meta.apply($mixin);

How It Works

$mixin holds a mixin value chosen at compile time. One meta.apply call includes whichever variant was selected.

🚀 Real-World Use Cases

  • Higher-order mixins — helpers like apply-to-all that accept any mixin value.
  • Design-token generators — loop sizes, colors, or breakpoints into one mixin.
  • Variant switching — choose solid vs outline (or theme A vs B) without duplicated includes.
  • Library APIs — let consumers pass a mixin value into your abstraction.
  • Content wrappers — forward @content into a dynamically chosen shell mixin.

🧠 How Compilation Works

1

Resolve a mixin value

Call meta.get-mixin("name") (or take a value from a map / argument).

Source
2

Include meta.apply

Pass the mixin value and any arguments (plus optional @content).

Compile
3

Mixin runs

Dart Sass expands the target mixin just like a normal @include.

Apply
4

Plain CSS ships

Browsers never see meta.apply—only the finished rules.

⚠️ Common Pitfalls

  • Passing a stringmeta.apply("font-class", 12px) is wrong. Resolve with meta.get-mixin first.
  • Using it as a value — do not write $x: meta.apply(...); always @include.
  • Confusing with meta.call — functions return values; mixins emit CSS.
  • Old Dart Sass — need 1.69+ for mixin values and meta.apply.
  • Wrong arity — argument count must match the applied mixin’s parameters (same rules as a normal include).

💡 Best Practices

✅ Do

  • Use @use "sass:meta" and @include meta.apply()
  • Resolve mixins with meta.get-mixin (or module maps)
  • Build small higher-order helpers like apply-to-all
  • Forward @content when wrappers need nested rules
  • Prefer Dart Sass 1.69+

❌ Don’t

  • Expect the browser to evaluate meta.apply
  • Pass a bare string as $mixin
  • Assign the include like a returning function
  • Use meta.call when you need CSS from a mixin
  • Rely on LibSass / Ruby Sass for this API

Key Takeaways

Knowledge Unlocked

Five things to remember about meta.apply()

Dynamic mixin include—mixin values, @include, Dart Sass 1.69+.

5
Core concepts
📦 02

Module

sass:meta

@use
🔗 03

Input

mixin value

Rule
04

vs call

mixins vs functions

Safe
05

Prefer

Dart Sass 1.69+

Tooling

❓ Frequently Asked Questions

meta.apply($mixin, $args...) includes a mixin value with the given arguments. Use it with @include. It is the mixin counterpart to meta.call(), which runs function values.
Usually with meta.get-mixin("name") for a mixin in the current module, or from meta.module-mixins($namespace). You cannot pass a plain string to meta.apply—pass a mixin value.
Yes. If you pass a @content block to @include meta.apply(...), that content is forwarded into the applied mixin.
It is a mixin from sass:meta. You include it with @include meta.apply(...). It emits CSS through the mixin it runs; it does not return a value like map.get.
meta.apply runs mixins (CSS / @content). meta.call runs functions (returns a value). Same idea—dynamic invocation—different Sass member types.
Dart Sass 1.69+. LibSass and Ruby Sass do not provide this meta mixin API. Prefer current Dart Sass.
Did you know?

Official Sass docs introduce meta.apply and meta.get-mixin together (Dart Sass 1.69). The same apply-to-all sample appears in both topics so you can see the resolve-then-include workflow in one place.

Conclusion

meta.apply() lets you include a mixin value with arguments—and optional @content—when the mixin is chosen dynamically. Resolve values with meta.get-mixin, always @include the apply mixin, and use Dart Sass 1.69+. Reach for meta.call when you need functions that return values instead.

Continue with meta.calc-args() or the Sass introduction.

Next: inspect calc arguments

Learn meta.calc-args() to open calc() and clamp() at compile time.

meta.calc-args() →

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