Sass meta.mixin-exists() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:meta · Dart Sass

What You’ll Learn

meta.mixin-exists() belongs to the built-in sass:meta module. It answers a simple question: is there a mixin named X? This page covers $module with @use, optional include patterns, safer alternatives to deprecated meta.feature-exists, and five compiled examples.

01

Concept

Is this mixin defined?

02

Module

@use "sass:meta"

03

Returns

true / false

04

$module

Check a @use namespace

05

vs others

function / get-mixin

06

Practice

5 examples

What Is meta.mixin-exists()?

Official docs: returns whether a mixin named $name exists. Use it when a library or theme wants an optional @mixin without crashing if that mixin is missing.

  • Without $module, Sass looks for a mixin without a namespace in the current file.
  • With $module, it looks inside a @use namespace from the current file.
  • Missing names return false—they do not throw.
💡
Beginner tip

Think of a toolbox: mixin-exists asks “do we have a hammer named shadow-none?” It does not swing the hammer—that is @include, or meta.get-mixin + meta.apply.

📝 Syntax

styles.scss
@use "sass:meta";

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

// Legacy global name (no $module argument)
mixin-exists($name)

Parameters

ParameterTypeRequiredDescription
$nameStringYesMixin name to look up (without parentheses or @mixin).
$moduleString or nullNoIf set, must match a @use namespace in the current file. Checks that module for $name.

Return value

TypeResult
Booleantrue if the mixin exists; otherwise false

📦 Loading sass:meta

styles.scss
// Recommended — namespaced
@use "sass:meta";
@use "utils";
$ok: meta.mixin-exists("center", $module: "utils");

// Optional — bring members into scope
@use "sass:meta" as *;
$ok: mixin-exists("shadow-none");

// Legacy global
$ok: mixin-exists("shadow-none");

🔗 Using the $module Argument

After @use "utils", mixins from that file live under the utils namespace. Check them with a module name:

styles.scss
@use "sass:meta";
@use "utils";

// Official style (positional $module)
@debug meta.mixin-exists("center", "utils"); // true

// Equivalent named argument
@debug meta.mixin-exists("center", $module: "utils"); // true

// Without $module, "center" is not defined in this file
@debug meta.mixin-exists("center"); // false

$module must match the namespace used in the current file. If you write @use "utils" as u, pass $module: "u".

📋 Related Meta Helpers

HelperChecksReturns
meta.mixin-existsMixinsBoolean
meta.function-existsFunctionsBoolean
meta.global-variable-existsGlobal variablesBoolean
meta.get-mixinMixinsMixin value (for meta.apply)
meta.feature-existsLegacy feature flagsBoolean — deprecated

🛠 Compatibility

This is about Sass compilers, not browsers. The lookup runs at compile time.

Implementationmixin-exists
Dart SassYes — prefer meta.mixin-exists with $module
LibSassYes (legacy global / limited modules)
Ruby SassYes (legacy global / limited modules)

Prefer current Dart Sass so @use namespaces work as shown in the docs.

⚡ Quick Reference

GoalCode
Import meta@use "sass:meta";
Local / current filemeta.mixin-exists("shadow-none")
Inside a modulemeta.mixin-exists("center", $module: "utils")
Optional include path@if meta.mixin-exists(…) { @include … }
Get the mixin valuemeta.get-mixin("shadow-none")
Check a function insteadmeta.function-exists("name")

Examples Gallery

Each example uses meta.mixin-exists at compile time. Open View Compiled CSS for verified Dart Sass output.

📚 Getting Started

Official-style lookups for custom and module mixins.

Example 1 — Custom Mixin Before and After

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

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

Matches the official docs idea: shadow-none is false until the @mixin is defined, then true.

Example 2 — Check a Mixin in Another Module

Use $module for mixins loaded with @use.

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

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

How It Works

center lives on the utils namespace, not as a free name in this file—so the bare check is false.

📈 Practical Patterns

Optional branches, pairing with meta.apply, and missing names.

Example 3 — Optional Mixin Path

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

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

Because soft-shadow is defined, the branch runs and the panel gets the shadow. Remove that 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).

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

mixin-exists avoids calling get-mixin on a missing name. When true, meta.apply includes the resolved mixin value.

Example 5 — Missing Names Return False

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

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

Typos fail closed. Only the correctly spelled module mixin returns true.

🚀 Real-World Use Cases

  • Optional theme hooks — include a user-provided @mixin only if it exists.
  • Module-aware libraries — detect mixins from a @use namespace via $module.
  • Safe dynamic APIs — guard meta.get-mixin + meta.apply.
  • Migration off feature-exists — preferred modern detection for mixin APIs.
  • Plugin registries — enable style features when a named mixin is present.

🧠 How Compilation Works

1

Pass a name (and optional module)

Call meta.mixin-exists("center", $module: "utils").

Source
2

Sass searches definitions

Looks in the current file or the named @use module.

Compile
3

Boolean drives @if

Your stylesheet keeps or skips optional mixin includes.

Branch
4

CSS ships

Browsers never see meta.mixin-exists—only finished rules.

⚠️ Common Pitfalls

  • Forgetting $module — a mixin from @use "utils" will not match a bare "center" check.
  • Wrong namespace string — must match the @use … as name in this file.
  • Confusing with get-mixin — exists returns a boolean; get-mixin returns a value.
  • Checking functions — use meta.function-exists instead.
  • Expecting runtime checks — everything resolves when Sass compiles.

💡 Best Practices

✅ Do

  • Use @use "sass:meta" and meta.mixin-exists()
  • Pass $module for namespaced mixins
  • Prefer this over deprecated feature-exists
  • Guard dynamic meta.apply paths
  • Prefer Dart Sass for module namespaces

❌ Don’t

  • Assume bare names find mixins from other @use files
  • Call get-mixin on unchecked names in optional APIs
  • Use it to detect functions or CSS browser support
  • Expect the browser to evaluate the check
  • Rely on typo-prone string names without tests

Key Takeaways

Knowledge Unlocked

Five things to remember about meta.mixin-exists()

Ask whether a mixin is defined—optionally inside a @use module.

5
Core concepts
📦 02

Module

sass:meta

@use
03

Returns

boolean

Result
🔗 04

$module

@use namespace

Scope
05

Next step

get-mixin + apply

Tooling

❓ 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".
Did you know?

Official Sass migration guidance for deprecated meta.feature-exists points authors toward meta.function-exists, meta.mixin-exists, and meta.global-variable-exists—member checks that stay useful as new APIs ship.

Conclusion

meta.mixin-exists() returns whether a named mixin is defined. Pass $module for @use namespaces, use it to guard optional includes, and pair it with meta.get-mixin / meta.apply when you need to include the mixin dynamically.

Continue with meta.module-functions() or the Sass introduction.

Next: list module functions

Learn meta.module-functions() to get every function in a @use module as a map.

meta.module-functions() →

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.

5 people found this page helpful