Sass meta.mixin-exists()

Intermediate
8 min read
Updated: Nov 2026
5 examples
Dart Sass

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

SCSS
@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.

Name and $module

How lookups work:

CallLooks inExample
meta.mixin-exists("shadow-none")Current scope (no namespace)User @mixin in this file
meta.mixin-exists("center", $module: "utils")The utils @use namespaceutils.center
Before defining the mixin—false
After @mixin / in moduleMatching scopetrue
vs other member checks.

Use meta.function-exists for functions and meta.global-variable-exists for globals. Prefer these over deprecated meta.feature-exists.

SCSS Examples

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

Example 1 — Custom Mixin Before and After

A name is missing until you define it (official shadow-none idea).

SCSS
@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;
}

How It Works

  1. Before the mixin, the check is false.
  2. @mixin shadow-none defines it.
  3. Afterward, the same check is true.
  4. Matches the official Sass docs sample idea.

Example 2 — Check a Mixin in Another Module

Use $module for mixins loaded with @use.

SCSS
@mixin center {
  display: grid;
  place-items: center;
}
SCSS
@use "sass:meta";
@use "utils";

.probe {
  --utils-center: #{meta.mixin-exists("center", $module: "utils")};
  --bare-center: #{meta.mixin-exists("center")};
}

How It Works

  1. @use "utils" loads the partial.
  2. $module: "utils" finds center.
  3. Bare "center" does not see the namespaced mixin.
  4. Match the namespace string used in this file.

Example 3 — Optional Mixin Path

Include a helper mixin when present; skip it when missing.

SCSS
@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);
}

How It Works

  1. soft-shadow is defined in this file.
  2. mixin-exists returns true.
  3. @include runs on that path.
  4. 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).

SCSS
@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;
  }
}

How It Works

  1. mixin-exists answers safely for a string name.
  2. get-mixin only runs on the true path.
  3. meta.apply includes the resolved mixin.
  4. Avoids throws from get-mixin on missing names.

Example 5 — Missing Names Return False

Unknown or mistyped names do not throw—they return false.

SCSS
@mixin center {
  display: grid;
  place-items: center;
}
SCSS
@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")};
}

How It Works

  1. Unknown names return false.
  2. Typos fail closed (no throw).
  3. Correct spelling in the module returns true.
  4. 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.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
meta.mixin-exists()Dart Sass via @use "sass:meta"
Return typeBoolean
Optional $moduleNamespace string or module value
Legacy globalmixin-exists($name) (no $module)

Compile with the Dart Sass CLI.

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).

Compile Notes

Practical checklist:

checklist.txt
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

meta.mixin-exists($name, $module: null) returns true if a mixin named $name is defined, otherwise false.
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".
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.
mixin-exists looks for mixins. function-exists looks for functions. Same idea, different member type.
Yes for detecting mixins. Official docs recommend function-exists, mixin-exists, and global-variable-exists instead of the deprecated feature-exists helper.
Yes. mixin-exists($name) is the legacy global form (no $module). Prefer meta.mixin-exists after @use "sass:meta".

Next: Sass meta.get-module()

Get a module that was already loaded with @use.

meta.get-module() →

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