Sass Mixin Values

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

Definition and Usage

Mixins are first-class values in Dart Sass 1.69+. Fetch one with meta.get-mixin(), keep it in a variable or map, hand it to another mixin, and include it later with @include meta.apply().

Because a mixin value is only a reference, you can build wrappers and dispatchers that accept any mixin—for example one that nests a mixin inside a selector.

Include with meta.apply.

A mixin value cannot be used with the plain @include name form. Use @include meta.apply($mixin, $args...), and pass a trailing { ... } block if the mixin takes @content.

Ask first.

meta.accepts-content() tells you whether a mixin value can receive a content block.

Compile-time only.

Mixin values never reach the CSS. Printing one fails; use meta.inspect() (it shows get-mixin("name")) when debugging.

Syntax

SCSS
@use "sass:meta";

@mixin center {
  display: grid;
  place-items: center;
}

$mixin: meta.get-mixin("center");

.hero {
  @include meta.apply($mixin);
}

// With arguments and a content block
@include meta.apply($mixin, $args...) { /* content */ }

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

Pattern: define a mixin → meta.get-mixin returns a value → pass or store it → @include meta.apply includes it.

Looking Up and Including Mixins

The core calls for mixin values:

GoalCode ideaResult
Look up a mixinmeta.get-mixin("center")Mixin value
Look up in a modulemeta.get-mixin("stretch", $module: "mixins")Module mixin value
Include a mixin value@include meta.apply($mixin)The mixin output
With arguments@include meta.apply($mixin, 8px)Arguments forwarded
Content block@include meta.apply($mixin) { ... }Block forwarded to @content
Check for @contentmeta.accepts-content($mixin)true / false
Whole catalogs.

meta.module-mixins() returns a map of every mixin in a module, each already a mixin value.

SCSS Examples

Examples target Dart Sass 1.69+. Open View Compiled CSS to see the included output.

Example 1 — Get a Mixin and Apply It

Store center in a variable and include it later.

SCSS
@use "sass:meta";

@mixin center {
  display: grid;
  place-items: center;
}

$mixin: meta.get-mixin("center");

.hero {
  @include meta.apply($mixin);
}

How It Works

  1. Define the mixin as usual.
  2. meta.get-mixin("center") returns a mixin value.
  3. @include meta.apply($mixin) includes it inside .hero.
  4. Output matches @include center.

Example 2 — Pass a Mixin to a Wrapper Mixin

A generic wrapper nests any mixin inside .wrap.

SCSS
@use "sass:meta";

@mixin center {
  display: grid;
  place-items: center;
}

@mixin pad($amount) {
  padding: $amount;
}

@mixin with-wrap($mixin, $args...) {
  .wrap {
    @include meta.apply($mixin, $args...);
  }
}

@include with-wrap(meta.get-mixin("pad"), 8px);
@include with-wrap(meta.get-mixin("center"));

How It Works

  1. with-wrap accepts any mixin value plus extra arguments.
  2. $args... forwards the arguments to meta.apply.
  3. First call passes 8px to pad.
  4. Second call passes none to center.

Example 3 — @content Blocks and accepts-content

Forward a block only when the mixin supports it.

SCSS
@use "sass:meta";

@mixin plain {
  display: block;
}

@mixin wrapper {
  .inner {
    @content;
  }
}

.card {
  @include meta.apply(meta.get-mixin("wrapper")) {
    color: red;
  }

  --plain-content: #{meta.accepts-content(meta.get-mixin("plain"))};
  --wrapper-content: #{meta.accepts-content(meta.get-mixin("wrapper"))};
}

How It Works

  1. wrapper uses @content; plain does not.
  2. The trailing block after meta.apply(...) is forwarded to @content.
  3. Output nests the block inside .card .inner.
  4. accepts-content reports false for plain and true for wrapper.

Example 4 — Keep Mixins in a Map

Pick a mixin by key at compile time.

SCSS
@use "sass:map";
@use "sass:meta";

@mixin light {
  color: #111;
}

@mixin dark {
  color: #eee;
}

$themes: (
  "light": meta.get-mixin("light"),
  "dark": meta.get-mixin("dark"),
);

.page {
  @include meta.apply(map.get($themes, "dark"));
}

How It Works

  1. Each map value is a mixin value.
  2. map.get($themes, "dark") fetches one by name.
  3. meta.apply includes it, emitting color: #eee.
  4. Add a theme by adding one entry.

Example 5 — Look Up a Mixin in a Module

Use $module to reach a mixin from a @used file.

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

.header {
  @include meta.apply(
    meta.get-mixin("stretch", $module: "mixins")
  );
}

How It Works

  1. @use "mixins" loads the file under the namespace mixins.
  2. $module: "mixins" tells meta.get-mixin where to look.
  3. meta.apply includes the returned value inside .header.
  4. Useful when the mixin name is chosen dynamically.

Edge Cases & Pitfalls

Most mixin-value mistakes are using plain @include, forgetting content support, or wrong names.

include

Use meta.apply, not @include $var

A mixin value must be included with @include meta.apply($mixin). There is no @include $mixin shorthand.

content

Content blocks need @content

A trailing block only makes sense when meta.accepts-content() is true.

name

Unknown names fail

meta.get-mixin("nope") is a compile error. Check with meta.mixin-exists() first.

version

Needs Dart Sass 1.69+

Older compilers do not have meta.get-mixin() or meta.apply().

Sass Support

Mixin values need a modern Dart Sass.

FeatureStatus
meta.get-mixin(), meta.apply()Dart Sass 1.69+
meta.accepts-content()Dart Sass 1.69+
meta.module-mixins()Dart Sass 1.69+
LibSass / Ruby SassNot supported

Compile with the Dart Sass CLI.

Key Takeaways

  • Mixins are values you can store, pass, and include later.
  • meta.get-mixin looks one up; @include meta.apply includes it.
  • Trailing blocks reach @content when the mixin supports it.
  • meta.module-mixins returns a map of a module’s mixin values.

One line: look up a mixin with meta.get-mixin(), then include it with @include meta.apply().

Compile Notes

Practical checklist:

checklist.txt
1. Use Dart Sass 1.69+
2. $m: meta.get-mixin("name")
3. @include meta.apply($m, args...)
4. Pass a trailing block only if accepts-content is true
5. Use $module to reach a mixin in a @use'd file

Frequently Asked Questions

A mixin value is a first-class reference to a mixin. You get one with meta.get-mixin() and include it with @include meta.apply().
Use @include meta.apply($mixin, $args...). The plain @include name syntax does not work for mixin values.
Yes. Add a trailing block after meta.apply(...) when the mixin uses @content. Check with meta.accepts-content() first.
Use meta.get-mixin("name", $module: "namespace") where namespace is the one from @use. meta.module-mixins() returns all of them as a map.
Dart Sass 1.69 and later added meta.get-mixin(), meta.apply(), meta.module-mixins(), and meta.accepts-content().
No. It is not valid CSS. Use meta.inspect() to see it as get-mixin("name") while debugging.

Next: Sass Module Values

Load a stylesheet as a value with meta.load() and meta.get-module().

Module Values →

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