Sass meta.apply()

Intermediate
9 min read
Updated: Nov 2026
5 examples
Dart Sass 1.69+

Definition and Usage

meta.apply($mixin, $args...) is a mixin that includes a mixin value with the given arguments. If you pass a @content block to @include meta.apply(...), that content is forwarded to $mixin. Load it with @use "sass:meta" on Dart Sass 1.69+.

Official sample idea.

Build an apply-to-all helper that loops a list and calls @include meta.apply($mixin, $element) for each item—for example generating .font-8px, .font-12px, and .font-2rem.

Mixin value required.

Pass a value from meta.get-mixin() or meta.module-mixins()—not a plain string name.

Include it—do not call it like a function.

Use @include meta.apply(...). It emits CSS; it does not return a value.

Syntax

SCSS
@use "sass:meta";

@include meta.apply($mixin, $args...);
@include meta.apply($mixin, $args...) { /* forwarded @content */ }

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

@include meta.apply(meta.get-mixin("font-class"), 12px);

// Module API — prefer meta.apply after @use "sass:meta"

Pattern: resolve a mixin value → @include meta.apply with args → optionally forward @content. Check meta.accepts-content first when content is optional.

apply vs call

Same dynamic idea, different member types:

HelperRunsHow you use it
meta.applyMixin value@include meta.apply(...) — emits CSS / can take @content
meta.callFunction valueExpression / assignment — returns a value
meta.get-mixin—Builds the mixin value you apply
meta.get-function—Builds the function value you call
Forwarding content.

If the target mixin cannot accept @content, do not pass a content block—or guard with meta.accepts-content.

SCSS Examples

Examples target Dart Sass 1.69+ with @use "sass:meta". Open View Compiled CSS for verified output (matches official Sass docs samples where shown).

Example 1 — Apply a Mixin Value Once

Resolve the mixin, then include it with one argument.

SCSS
@use "sass:meta";

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

@include meta.apply(meta.get-mixin("font-class"), 12px);

How It Works

  1. get-mixin returns a mixin value.
  2. meta.apply includes it with 12px.
  3. CSS emits from the target mixin.
  4. Same idea as @include font-class(12px), but dynamic.

Example 2 — Official Docs apply-to-all

Loop a list and apply the same mixin to each element.

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

  1. Higher-order mixin receives a mixin value + list.
  2. @each walks every size.
  3. meta.apply runs font-class per item.
  4. Matches the official Sass docs CSS output.

Example 3 — Forward a @content Block

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

SCSS
@use "sass:meta";

@mixin with-content {
  .inner {
    @content;
  }
}

.wrap {
  @include meta.apply(meta.get-mixin("with-content")) {
    color: red;
  }
}

How It Works

  1. Target mixin declares @content.
  2. Caller passes a content block to meta.apply.
  3. Sass forwards that block into the mixin.
  4. Result nests color: red under .inner.

Example 4 — Guard Content with accepts-content

Only forward a content block when the mixin can take one.

SCSS
@use "sass:meta";

@mixin plain {
  color: blue;
}

@mixin with-content {
  .inner {
    @content;
  }
}

@mixin apply-if-content($mixin) {
  @if meta.accepts-content($mixin) {
    @include meta.apply($mixin) {
      outline: 1px solid red;
    }
  } @else {
    @include meta.apply($mixin);
  }
}

.a {
  @include apply-if-content(meta.get-mixin("plain"));
}

.b {
  @include apply-if-content(meta.get-mixin("with-content"));
}

How It Works

  1. Check capability first.
  2. Plain mixins get a content-free apply.
  3. Content mixins receive the outline block.
  4. Safer for reusable higher-order helpers.

Example 5 — Pass Multiple Arguments

Extra args after the mixin value are forwarded to the mixin signature.

SCSS
@use "sass:meta";

@mixin card($pad, $radius) {
  .card {
    padding: $pad;
    border-radius: $radius;
  }
}

@include meta.apply(meta.get-mixin("card"), 1rem, 8px);

How It Works

  1. First argument is the mixin value.
  2. Remaining args match the mixin parameters.
  3. 1rem and 8px fill $pad and $radius.
  4. Argument count must still satisfy the mixin.

Edge Cases & Pitfalls

Most apply bugs are string names, wrong include syntax, or content forwarding into plain mixins.

type

Pass a mixin value

meta.apply("font-class", 12px) fails. Use meta.get-mixin("font-class").

include

Must use @include

meta.apply is a mixin. Do not assign its result like a function.

content

Content needs a capable mixin

Guard with meta.accepts-content when content is optional.

vs

Functions use meta.call

Dynamic functions return values via meta.call, not meta.apply.

Sass Support

Prefer the module form with Dart Sass 1.69+.

APIStatus
meta.apply()Dart Sass 1.69+ via @use "sass:meta"
KindMixin (use with @include)
First argumentMixin value (e.g. from meta.get-mixin)
LibSass / Ruby SassNot available

Compile with the Dart Sass CLI.

Key Takeaways

  • Dynamically includes a mixin value with args.
  • Forwards @content when you pass a content block.
  • Pair with get-mixin; use call for functions.
  • Dart Sass 1.69+ via @use "sass:meta".

One line: when a mixin value must be included dynamically (with optional content), call @include meta.apply($mixin, $args...).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. Resolve a mixin value (get-mixin / module-mixins)
3. @include meta.apply($mixin, $args...)
4. Optionally forward @content (guard with accepts-content)
5. Use meta.call for function values

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.

Next: Sass meta.calc-args()

Inspect the arguments inside a CSS calculation value.

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.

8 people found this page helpful