Sass meta.get-mixin()

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

Definition and Usage

meta.get-mixin($name, $module: null) returns a mixin value for the named mixin. Include it with @include meta.apply(). Load it with @use "sass:meta" on Dart Sass 1.69+.

Official sample idea.

Build an apply-to-all helper that receives meta.get-mixin("font-class") and calls @include meta.apply($mixin, $element) for each list item.

$module for namespaces.

Pass a string matching a @use namespace, or a module value, to resolve mixins from that module.

Missing names throw.

Official docs: if $name is not a mixin, Sass errors. Guard optional names with meta.mixin-exists first.

Syntax

SCSS
@use "sass:meta";

meta.get-mixin($name, $module: null); //=> mixin

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

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

@include meta.apply(meta.get-mixin("wrap")) {
  // forwarded @content
}

// Module API — prefer meta.get-mixin after @use "sass:meta"

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

get-mixin vs get-function

Same resolve idea, different member types:

HelperReturnsThen use
meta.get-mixinMixin value@include meta.apply(...) — emits CSS / can take @content
meta.get-functionFunction valuemeta.call(...) — returns a value
meta.mixin-existsBooleanSafe optional check before get-mixin
meta.module-mixinsMap of mixin valuesPick a mixin with map.get, then apply
No $css flag.

Unlike get-function, mixins are Sass-only. There is no “plain CSS mixin” mode.

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 — Resolve and Apply Once

Get a mixin value, 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

Pass a mixin value into a helper that applies it to each list item.

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. get-mixin captures font-class.
  2. Higher-order mixin receives that value + list.
  3. Each size is applied separately.
  4. Matches the official Sass docs CSS output.

Example 3 — Forward a @content Block

Content passed to meta.apply is forwarded into the resolved 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. get-mixin resolves the content-capable mixin.
  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

Forward a content block only when the resolved mixin can take one.

SCSS
@use "sass:meta";

@mixin plain {
  color: blue;
}

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

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

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

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

How It Works

  1. get-mixin resolves by string name.
  2. accepts-content checks capability.
  3. Plain mixins get a content-free apply.
  4. Content mixins receive the outline block.

Example 5 — Guard with mixin-exists

Avoid a throw when the mixin name might be missing.

SCSS
@use "sass:meta";

@mixin badge {
  .badge {
    display: inline-block;
  }
}

.exists {
  @if meta.mixin-exists("badge") {
    @include meta.apply(meta.get-mixin("badge"));
  }
}

How It Works

  1. mixin-exists answers yes/no safely.
  2. get-mixin only runs on the true path.
  3. apply emits the badge rule.
  4. Safer for optional plugin-style mixins.

Edge Cases & Pitfalls

Most get-mixin bugs are missing names, forgetting apply, or confusing functions with mixins.

missing

Unknown names throw

Use meta.mixin-exists before resolving optional mixins.

include

Resolve ≠ include

You still need @include meta.apply($mixin, …) to emit CSS.

module

Namespaced mixins need $module

Match the @use namespace string, or pass a module value.

vs

Functions use get-function

Dynamic functions return values via meta.get-function + meta.call.

Sass Support

Prefer the module form with Dart Sass 1.69+.

APIStatus
meta.get-mixin()Dart Sass 1.69+ via @use "sass:meta"
Return typeMixin value
Include with@include meta.apply($mixin, $args...)
LibSass / Ruby SassNot available

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns a mixin value for a name (and optional module).
  • Include with meta.apply; content blocks are forwarded.
  • Pair with mixin-exists / accepts-content for safe dynamic includes.
  • Dart Sass 1.69+ via @use "sass:meta".

One line: when you need a mixin value to pass around or include dynamically, use meta.get-mixin($name, $module: null).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. meta.get-mixin("name") or with $module
3. @include meta.apply($mixin, $args...)
4. Optionally forward @content (guard with accepts-content)
5. Prefer mixin-exists before optional lookups

Frequently Asked Questions

meta.get-mixin($name, $module: null) returns a mixin value for the named mixin. You include that value with @include meta.apply($mixin, $args...).
When the mixin lives under a @use namespace. $module must match that namespace string in the current file, or you can pass a module value.
get-mixin resolves mixins (for meta.apply / CSS). get-function resolves functions (for meta.call / returned values).
Official docs: get-mixin throws if $name does not refer to a mixin. Guard optional names with meta.mixin-exists first.
get-mixin only resolves the mixin. When you @include meta.apply($mixin) { … }, that content block is forwarded into the applied mixin.
Dart Sass 1.69+. LibSass and Ruby Sass do not provide this API. Prefer current Dart Sass.

Next: Sass meta.global-variable-exists()

Check whether a global variable name is defined.

meta.global-variable-exists() →

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