Home Sass Meta meta.mixin-exists() Definition
Definition and Usage meta.mixin-exists($name, $module: null) returns a boolean : whether a mixin named $name is defined. Load it with @use "sass:meta".
Official sample. meta.mixin-exists("shadow-none") is false until you define @mixin shadow-none, then true.
Pass $module for namespaces. After @use "utils", check module members with $module: "utils". The value can also be a module value.
Yes/no only. To include the mixin dynamically, use meta.get-mixin plus meta.apply . Guard optional names with mixin-exists first.
Syntax
Syntax @use "sass:meta";
meta.mixin-exists($name, $module: null); //=> boolean
meta.mixin-exists("shadow-none"); // false until defined
@mixin shadow-none { box-shadow: none; }
meta.mixin-exists("shadow-none"); // true
meta.mixin-exists("center", $module: "utils"); // after @use "utils"
// Global alias (legacy): mixin-exists($name) — no $module
// Prefer meta.mixin-exists after @use "sass:meta" Pattern: choose a name (and optional module) → check mixin-exists → branch or call get-mixin / @include.
Code
SCSS Examples Examples use @use "sass:meta". Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).
1. Basic 2. $module 3. Optional 4. get-mixin 5. Missing Example 1 — Custom Mixin Before and After A name is missing until you define it (official shadow-none idea).
@use "sass:meta";
.before {
--shadow: #{meta.mixin-exists("shadow-none")};
}
@mixin shadow-none {
box-shadow: none;
}
.after {
--shadow: #{meta.mixin-exists("shadow-none")};
}
.btn {
@include shadow-none;
} .before {
--shadow: false;
}
.after {
--shadow: true;
}
.btn {
box-shadow: none;
} How It Works Before the mixin, the check is false.@mixin shadow-none defines it.Afterward , the same check is true.Matches the official Sass docs sample idea.Example 2 — Check a Mixin in Another Module Use $module for mixins loaded with @use.
@mixin center {
display: grid;
place-items: center;
} @use "sass:meta";
@use "utils";
.probe {
--utils-center: #{meta.mixin-exists("center", $module: "utils")};
--bare-center: #{meta.mixin-exists("center")};
} .probe {
--utils-center: true;
--bare-center: false;
} How It Works @use "utils" loads the partial.$module: "utils" finds center.Bare "center" does not see the namespaced mixin.Match the namespace string used in this file.Example 3 — Optional Mixin Path Include a helper mixin when present; skip it when missing.
@use "sass:meta";
@mixin soft-shadow {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
@mixin card($pad: 1rem) {
@if meta.mixin-exists("soft-shadow") {
@include soft-shadow;
}
padding: $pad;
}
.panel {
@include card(1.25rem);
} .panel {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
padding: 1.25rem;
} How It Works soft-shadow is defined in this file.mixin-exists returns true.@include runs on that path.Remove the mixin and the card still compiles with padding only.Example 4 — Exists, Then get-mixin + apply Guard dynamic includes with a boolean check first (Dart Sass 1.69+ for get-mixin / apply).
@use "sass:meta";
@mixin elevate {
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}
$name: "elevate";
.card {
@if meta.mixin-exists($name) {
@include meta.apply(meta.get-mixin($name));
} @else {
box-shadow: none;
}
} .card {
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
} How It Works mixin-exists answers safely for a string name.get-mixin only runs on the true path.meta.apply includes the resolved mixin.Avoids throws from get-mixin on missing names.Example 5 — Missing Names Return False Unknown or mistyped names do not throw—they return false.
@mixin center {
display: grid;
place-items: center;
} @use "sass:meta";
@use "utils";
.flags {
--nope: #{meta.mixin-exists("definitely-missing")};
--typo: #{meta.mixin-exists("centerr", $module: "utils")};
--ok: #{meta.mixin-exists("center", $module: "utils")};
} .flags {
--nope: false;
--typo: false;
--ok: true;
} How It Works Unknown names return false.Typos fail closed (no throw).Correct spelling in the module returns true.Safe for optional plugin-style mixins. Edge Cases & Pitfalls Most mixin-exists bugs are forgetting $module or confusing it with get-mixin.
module Namespaced mixins need $module A bare check will not see members under a @use namespace.
vs Exists ≠ include Use meta.get-mixin + meta.apply (or a normal @include) to emit CSS.
order Define before you check Like the official sample, a name is false until the @mixin appears above the check’s evaluation.
legacy Prefer the module API Global mixin-exists($name) has no $module. Prefer meta.mixin-exists.
Toolchain
Sass Support Prefer the module form with current Dart Sass.
API Status meta.mixin-exists()Dart Sass via @use "sass:meta" Return type Boolean Optional $module Namespace string or module value Legacy global mixin-exists($name) (no $module)
Compile with the Dart Sass CLI .
Remember
Key Takeaways Returns true/false for whether a mixin name is defined.
Use $module to check mixins under a @use namespace.
Pair with get-mixin / apply for safe dynamic includes.
Prefer over feature-exists for mixin detection.
One line: to ask whether a mixin is defined, use meta.mixin-exists($name, $module: null).
Practice
Compile Notes Practical checklist:
1. @use "sass:meta"
2. meta.mixin-exists("name") or with $module
3. @if … { @include … } for optional paths
4. Guard get-mixin with exists first
5. Prefer this over deprecated feature-exists Frequently Asked Questions What does Sass meta.mixin-exists() do? meta.mixin-exists($name, $module: null) returns true if a mixin named $name is defined, otherwise false.
When do I pass $module? When the mixin lives in a @use namespace. $module must match that namespace string—for example meta.mixin-exists("center", $module: "utils") after @use "utils".
How is it different from meta.get-mixin? mixin-exists only answers yes/no. get-mixin returns the mixin value so you can include it with meta.apply. Use exists first for optional mixin names.
How is it different from meta.function-exists? mixin-exists looks for mixins. function-exists looks for functions. Same idea, different member type.
Should I use this instead of feature-exists? Yes for detecting mixins. Official docs recommend function-exists, mixin-exists, and global-variable-exists instead of the deprecated feature-exists helper.
Is there a global mixin-exists()? Yes. mixin-exists($name) is the legacy global form (no $module). Prefer meta.mixin-exists after @use "sass:meta".
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.
8 people found this page helpful
Helpful Share Copy link Suggestion