Home Sass Functions meta meta.get-mixin() Overview
What You’ll Learn meta.get-mixin() belongs to the built-in sass:meta module. It turns a mixin name into a mixin value you can store, pass around, and include with meta.apply . This page covers $module, @content, vs get-function , Dart Sass 1.69+, and five compiled examples.
01
Concept Name → mixin value
04
Include @include meta.apply
Concept
What Is meta.get-mixin()? Normally you write @include card; with a fixed name. Higher-order helpers need a reference to a mixin instead. Official docs: meta.get-mixin returns the mixin value named $name, and you include it with meta.apply().
Without $module, looks up a mixin defined in the current module. With $module, looks inside a @use namespace from the current file. Missing names throw by default—use meta.mixin-exists for optional APIs. 💡
Beginner tip get-mixin picks a tool from the toolbox. meta.apply uses it (and can forward @content). For functions, the cousins are meta.get-function and meta.call.
Foundation
📝 Syntax @use "sass:meta";
// Recommended — Dart Sass 1.69+
meta.get-mixin($name, $module: null) Parameters Parameter Type Required Description $nameString Yes Mixin name to resolve (without parentheses). $moduleString or null No If set, must match a @use namespace in the current file.
Return value Type Result Mixin value A mixin you include with @include meta.apply($mixin, …)
Unlike meta.get-function, there is no $css flag—mixin names must resolve to real Sass mixins.
Modules
📦 Loading sass:meta // Recommended — namespaced
@use "sass:meta";
@mixin stamp {
color: teal;
}
$m: meta.get-mixin("stamp");
.box {
@include meta.apply($m);
}
// Optional — bring members into scope
@use "sass:meta" as *;
$m: get-mixin("stamp");
@include apply($m);
// Alias
@use "sass:meta" as m;
$m: m.get-mixin("stamp");
@include m.apply($m); Details
🔗 Pair with meta.apply Official rule: the returned mixin is included using meta.apply(). Remember apply is a mixin —always use @include.
@use "sass:meta";
@mixin pad($n) {
padding: $n;
}
$mx: meta.get-mixin("pad");
.card {
@include meta.apply($mx, 1rem);
}
// Optional @content is forwarded into the applied mixin
@include meta.apply($mx, 0.5rem) {
// only useful if the target mixin uses @content
} Compare
📋 Related Meta Helpers Helper Role meta.mixin-existsBoolean: is the mixin defined? meta.get-mixinMixin value: resolve the reference meta.applyInclude a mixin value (CSS / @content) meta.accepts-contentCan this mixin value take @content? meta.get-function + meta.callSame idea for functions / returned values
Support
🛠 Compatibility This is about Sass compilers , not browsers. Resolution runs at compile time.
Implementation meta.get-mixin()Notes Dart Sass (1.69+) Yes — required Mixin values + meta.apply landed in 1.69.0 LibSass No No modern mixin-value API Ruby Sass No Legacy—prefer Dart Sass
Prefer current Dart Sass 1.69+ for get-mixin and apply.
Cheat Sheet
⚡ Quick Reference Goal Code Import meta @use "sass:meta";Local mixin meta.get-mixin("card")Module mixin meta.get-mixin("name", $module: "ns")Include it @include meta.apply($mx, $arg)Forward content @include meta.apply($mx) { … }Safe optional path @if meta.mixin-exists(…) { get-mixin … }
Hands-On
Examples Gallery Each example resolves a mixin value, then includes it with meta.apply. Open View Compiled CSS for verified Dart Sass output (1.69+).
basic loop choose content guard 📚 Getting Started Simple resolve + apply, and the official apply-to-all pattern.
Example 1 — Basic get-mixin + apply Resolve a local mixin, store it, then include it.
@use "sass:meta";
@mixin stamp {
color: teal;
font-weight: 700;
}
$mx: meta.get-mixin("stamp");
.box {
@include meta.apply($mx);
} .box {
color: teal;
font-weight: 700;
} How It Works $mx holds a mixin value, not a string. @include meta.apply($mx) is equivalent to @include stamp.
Example 2 — Apply One Mixin to Many Values (Official Docs) Pass meta.get-mixin("font-class") into a higher-order helper.
@use "sass:meta";
@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); .font-8px {
font-size: 8px;
}
.font-12px {
font-size: 12px;
}
.font-2rem {
font-size: 2rem;
} How It Works apply-to-all never hard-codes font-class. It receives a mixin value from get-mixin and includes it once per list item.
📈 Practical Patterns Choosing a mixin, forwarding @content, and safe guards.
Example 3 — Choose a Mixin Dynamically Pick one of two local mixins, then apply the chosen value.
@use "sass:meta";
@mixin solid {
border: 2px solid #334155;
}
@mixin dashed {
border: 2px dashed #94a3b8;
}
$style: "solid";
$mx: if(
$style == "solid",
meta.get-mixin("solid"),
meta.get-mixin("dashed")
);
.panel {
@include meta.apply($mx);
} .panel {
border: 2px solid #334155;
} How It Works One meta.apply site serves either border style. Flip $style without rewriting the include line.
Example 4 — Forward @content Through apply Resolve a wrapper mixin, then pass a content block into meta.apply.
@use "sass:meta";
@mixin frame {
border: 1px solid #cbd5e1;
padding: 1rem;
@content;
}
$mx: meta.get-mixin("frame");
.card {
@include meta.apply($mx) {
color: #0f172a;
}
} .card {
border: 1px solid #cbd5e1;
padding: 1rem;
color: #0f172a;
} How It Works get-mixin only resolves the mixin. @include meta.apply($mx) { … } forwards the content block into frame’s @content.
Example 5 — Guard with mixin-exists + accepts-content Only resolve and apply when the mixin exists and can take content.
@use "sass:meta";
@mixin shell {
display: block;
@content;
}
$name: "shell";
.widget {
@if meta.mixin-exists($name) {
$mx: meta.get-mixin($name);
@if meta.accepts-content($mx) {
@include meta.apply($mx) {
margin: 1rem;
}
} @else {
@include meta.apply($mx);
}
}
} .widget {
display: block;
margin: 1rem;
} How It Works mixin-exists avoids a missing-name error. accepts-content decides whether forwarding a content block is safe.
Applications
🚀 Real-World Use Cases Higher-order mixins — apply one mixin across a list of tokens (official apply-to-all).Theme switches — choose solid/dashed (or brand variants) from config.Plugin APIs — accept a mixin value from consumers instead of a fixed name.Content-aware wrappers — resolve, check accepts-content, then forward blocks.Module bridging — pull mixins from another @use namespace via $module.🧠 How Compilation Works 1
Resolve by name Call meta.get-mixin("name") (optionally with $module).
Source
2
Hold a mixin value Store it or pass it into another mixin / helper.
Value
3
Include with meta.apply Forward arguments and optional @content.
Apply
4
✓ CSS ships Browsers never see get-mixin—only finished CSS.
Watch Out
⚠️ Common Pitfalls Treating apply like a function — always @include meta.apply(…).Missing name — throws; guard with meta.mixin-exists.Wrong $module — must match this file’s @use … as name.Confusing with get-function — mixins emit CSS; functions return values.Old Dart Sass — needs 1.69+ for mixin values.Pro Tips
💡 Best Practices ✅ Do Use @use "sass:meta" and meta.get-mixin() Include results with @include meta.apply Pass $module for namespaced mixins Guard optional names with mixin-exists Target Dart Sass 1.69+ ❌ Don’t Pass a plain string to meta.apply Assign meta.apply(…) like a returned value Expect LibSass / Ruby Sass support Forward @content without checking accepts-content in shared APIs Expect the browser to resolve mixin values Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about meta.get-mixin() Resolve a mixin value by name, then include it with meta.apply.
📝 01
API get-mixin($name)
Call 📦 02
Module sass:meta
@use 🔗 03
Returns mixin value
Result ⚙ 04
Include meta.apply
Next ✓ 05
Since Dart Sass 1.69+
Req ❓ Frequently Asked Questions What does Sass meta.get-mixin() do? 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 do I pass $module? When the mixin lives under a @use namespace. $module must match that namespace string in the current file.
How is it different from meta.get-function? get-mixin resolves mixins (for meta.apply / CSS). get-function resolves functions (for meta.call / returned values).
What if the name is missing? Official docs: by default get-mixin throws if $name does not refer to a mixin. Guard optional names with meta.mixin-exists first.
Does it support @content? get-mixin only resolves the mixin. When you @include meta.apply($mixin) { … }, that content block is forwarded into the applied mixin.
Which compilers support meta.get-mixin? Dart Sass 1.69+. LibSass and Ruby Sass do not provide this API. Prefer current Dart Sass.
Did you know?
Official Sass docs use the same apply-to-all + font-class sample for both meta.get-mixin and meta.apply: resolve the mixin once, pass the mixin value into the helper, and let meta.apply include it for every list item.
Wrap Up
Conclusion meta.get-mixin() turns a mixin name into a reusable mixin value. Pass $module for @use namespaces, include the result with @include meta.apply, and use mixin-exists / accepts-content for safer shared APIs on Dart Sass 1.69+.
Continue with meta.global-variable-exists() or the Sass introduction .
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion