Sass meta.function-exists()

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

Definition and Usage

meta.function-exists($name, $module: null) returns a boolean: whether a function named $name is defined—either as a built-in or a user-defined function. Load it with @use "sass:meta".

Official samples.

meta.function-exists("div", $module: "math") → true · meta.function-exists("scale-color") → true · meta.function-exists("add") → false until you define @function add.

Pass $module for namespaces.

After @use "sass:math", check module members with $module: "math". The $module value can also be a module value.

Yes/no only.

To run the function, use meta.get-function plus meta.call.

Syntax

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

meta.function-exists($name, $module: null); //=> boolean

meta.function-exists("div", $module: "math"); // true
meta.function-exists("scale-color");          // true
meta.function-exists("add");                  // false (until defined)

// Global alias (legacy): function-exists($name)
// Prefer meta.function-exists after @use "sass:meta"

Pattern: choose a name (and optional module) → check function-exists → branch or call get-function.

Name and $module

How lookups work:

CallLooks inExample
meta.function-exists("add")Current scope / global built-ins (no namespace)User @function or global built-in
meta.function-exists("div", $module: "math")The math @use namespacemath.div
Before defining add—false
After @function addSame file / scopetrue
vs mixin / variable helpers.

Use meta.mixin-exists for mixins 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 output (matches official Sass docs samples where shown).

Example 1 — Official Docs Sample ($module)

Check a namespaced math helper after @use.

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

@debug meta.function-exists("div", $module: "math"); // true

.module-demo {
  --div: #{meta.function-exists("div", $module: "math")};
}

How It Works

  1. @use "sass:math" loads the module.
  2. $module: "math" scopes the lookup.
  3. div exists as math.div.
  4. Matches the official Sass docs sample.

Example 2 — Official Docs Sample (Global Built-in)

Without $module, Sass checks the un-namespaced name.

SCSS
@use "sass:meta";

@debug meta.function-exists("scale-color"); // true

.builtin {
  --scale: #{meta.function-exists("scale-color")};
}

How It Works

  1. No module argument is passed.
  2. Global built-in scale-color is found.
  3. Result is true.
  4. Matches the official Sass docs sample.

Example 3 — Official Docs Sample (Define Then Recheck)

add is false until you define it, then true.

SCSS
@use "sass:meta";

.before {
  --add: #{meta.function-exists("add")}; // false
}

@function add($num1, $num2) {
  @return $num1 + $num2;
}

.after {
  --add: #{meta.function-exists("add")}; // true
}

How It Works

  1. Before the function, the name is unknown.
  2. @function add registers it.
  3. After, the same check returns true.
  4. Matches the official Sass docs sample.

Example 4 — Guard Before Using an API

Branch only when a module function is available.

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

.guard {
  @if meta.function-exists("div", $module: "math") {
    width: math.div(100px, 4);
  }
}

How It Works

  1. Check for math.div.
  2. True path uses the modern division helper.
  3. Compiled width is 25px.
  4. Useful in shared libraries targeting mixed Sass versions.

Example 5 — Pair with get-function / call

Exists answers yes/no; get-function + call invoke it.

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

.pair {
  @if meta.function-exists("abs", $module: "math") {
    --abs: #{meta.call(meta.get-function("abs", $module: "math"), -8px)};
  }
}

How It Works

  1. Exists confirms the member.
  2. get-function returns a function value.
  3. call invokes it with -8px.
  4. Safer than calling a name that might be missing.

Edge Cases & Pitfalls

Most function-exists bugs are forgetting $module or confusing exists with get-function.

module

Namespaced APIs need $module

meta.function-exists("div") is not the same as checking math.div. Pass $module: "math".

order

Definition order matters

A user function only exists after its @function appears for that lookup point.

invoke

Exists does not call

Use meta.get-function + meta.call to run it.

vs

Wrong helper for mixins

Use meta.mixin-exists for mixin names.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
meta.function-exists()Dart Sass via @use "sass:meta"
Global function-exists()Legacy; no $module parameter—prefer module form
Arguments$name (string), optional $module
Return typeBoolean

Compile with the Dart Sass CLI.

Key Takeaways

  • Boolean check for built-in or user functions.
  • Use $module for @use namespaces.
  • Pair with get-function / call when you need to invoke.
  • Preferred over feature-exists for API detection.

One line: when you need to know if a function name is defined before using it, call meta.function-exists($name, $module: null).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. Pass the function name as a string
3. Add $module for @use namespaces
4. Branch on the boolean result
5. Use get-function + call to invoke

Frequently Asked Questions

meta.function-exists($name, $module: null) returns true if a function named $name is defined as a built-in or user-defined function, otherwise false.
When the function lives in a @use namespace. $module must match that namespace string—for example meta.function-exists("div", $module: "math") after @use "sass:math".
function-exists only answers yes/no. get-function returns the function value so you can run it with meta.call. Use exists first if you need a safe optional path.
function-exists looks for functions. mixin-exists looks for mixins. Same idea, different member type.
Yes for detecting APIs. Official docs recommend function-exists, mixin-exists, and global-variable-exists instead of the deprecated feature-exists helper.
Yes. function-exists($name) is the legacy global form (no $module). Prefer meta.function-exists after @use "sass:meta".

Next: Sass meta.get-function()

Turn a function name into a value you can pass to meta.call.

meta.get-function() →

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