Sass meta.function-exists() Function

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

What You’ll Learn

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

01

Concept

Is this function defined?

02

Module

@use "sass:meta"

03

Returns

true / false

04

$module

Check a @use namespace

05

vs others

mixin / get-function

06

Practice

5 examples

What Is meta.function-exists()?

Official docs: returns whether a function named $name is defined—either a built-in or a user-defined @function. Use it when a library or theme wants an optional helper without crashing if that helper is missing.

  • Without $module, Sass looks for a function in the current global / local scope (including many built-ins).
  • 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 phone book: function-exists asks “is there an entry named abs?” It does not dial the number—that is meta.get-function + meta.call.

📝 Syntax

styles.scss
@use "sass:meta";

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

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

Parameters

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

Return value

TypeResult
Booleantrue if the function exists; otherwise false

📦 Loading sass:meta

styles.scss
// Recommended — namespaced
@use "sass:meta";
@use "sass:math";
$ok: meta.function-exists("pow", $module: "math");

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

// Legacy global
$ok: function-exists("lighten");

🔗 Using the $module Argument

After @use "sass:math", functions like pow live under the math namespace. Official docs check them with a module name:

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

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

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

// Without $module, "div" is not a free global name in modern Sass
@debug meta.function-exists("div"); // false

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

📋 Related Meta Helpers

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

🛠 Compatibility

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

Implementationfunction-exists
Dart SassYes — prefer meta.function-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 / global namemeta.function-exists("add")
Inside a modulemeta.function-exists("pow", $module: "math")
Optional call path@if meta.function-exists(…) { … }
Get the function valuemeta.get-function("add")
Check a mixin insteadmeta.mixin-exists("name")

Examples Gallery

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

📚 Getting Started

Official-style lookups for custom and module functions.

Example 1 — Custom Function Before and After

A name is missing until you define it in the same stylesheet.

styles.scss
@use "sass:meta";

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

@function add($a, $b) {
  @return $a + $b;
}

.after {
  --add: #{meta.function-exists("add")};
  width: add(20px, 20px);
}

How It Works

Matches the official docs idea: add is false until the @function is defined, then true.

Example 2 — Check a Built-in Module Function

Use $module for sass:math members like div and pow.

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

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

How It Works

div exists on the math namespace, not as a free global name in the module system—so the bare check is false.

📈 Practical Patterns

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

Example 3 — Optional Math Path

Use a module function when present; otherwise fall back.

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

@function scale-size($n) {
  @if meta.function-exists("pow", $module: "math") {
    @return math.pow($n, 2) * 1px;
  }
  @return $n * $n * 1px;
}

.box {
  width: scale-size(4);
}

How It Works

On Dart Sass, math.pow exists, so the first branch runs. The fallback keeps older environments from breaking if you ever needed it.

Example 4 — Exists, Then get-function + call

Guard dynamic invocation with a boolean check first.

styles.scss
@use "sass:meta";

@function double($n) {
  @return $n * 2;
}

$name: "double";

.box {
  @if meta.function-exists($name) {
    width: meta.call(meta.get-function($name), 48px);
  } @else {
    width: 48px;
  }
}

How It Works

function-exists avoids calling get-function on a missing name. When true, meta.call runs the resolved function value.

Example 5 — Missing Names Return False

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

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

.flags {
  --nope: #{meta.function-exists("definitely-missing")};
  --typo-pow: #{meta.function-exists("poww", $module: "math")};
  --scale-color: #{meta.function-exists("scale-color")};
}

How It Works

Typos fail closed. scale-color is still a recognizable global built-in in Sass (as in the official docs example), so it returns true.

🚀 Real-World Use Cases

  • Optional theme hooks — call a user-provided @function only if it exists.
  • Module-aware libraries — detect sass:math / sass:color helpers via $module.
  • Safe dynamic APIs — guard meta.get-function + meta.call.
  • Migration off feature-exists — preferred modern detection for function APIs.
  • Plugin registries — enable features when a named helper is present.

🧠 How Compilation Works

1

Pass a name (and optional module)

Call meta.function-exists("pow", $module: "math").

Source
2

Sass searches definitions

Looks in global/local scope or the named @use module.

Compile
3

Boolean drives @if

Your stylesheet keeps or skips optional function paths.

Branch
4

CSS ships

Browsers never see meta.function-exists—only finished values.

⚠️ Common Pitfalls

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

💡 Best Practices

✅ Do

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

❌ Don’t

  • Assume bare names find sass:math members
  • Call get-function on unchecked names in optional APIs
  • Use it to detect mixins 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.function-exists()

Ask whether a function 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-function + call

Tooling

❓ 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("pow", $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".
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.function-exists() returns whether a named function is defined. Pass $module for @use namespaces, use it to guard optional helpers, and pair it with meta.get-function / meta.call when you need to run the function dynamically.

Continue with meta.get-function() or the Sass introduction.

Next: resolve a function value

Learn meta.get-function() to get a callable function reference.

meta.get-function() →

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