Sass meta.get-function()

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

Definition and Usage

meta.get-function($name, $css: false, $module: null) returns a function value for the named function. Invoke it with meta.call(). Load it with @use "sass:meta".

Official sample idea.

Pass meta.get-function("contains-helvetica") into a higher-order helper that uses meta.call($condition, $element)—for example filtering font names.

$module for namespaces.

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

Missing names.

By default, an unknown Sass function throws. With $css: true, Sass returns a plain CSS function instead. Do not combine $css: true with $module.

Syntax

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

meta.get-function($name, $css: false, $module: null); //=> function

meta.call(meta.get-function("abs", $module: "math"), -12px); // 12px
meta.call(meta.get-function("blur", $css: true), 4px);       // blur(4px)

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

Pattern: resolve a function value → meta.call with args → use the result. Check first with meta.function-exists when the API is optional.

$module and $css

How the options change lookup:

OptionsBehavior
DefaultUn-namespaced Sass function (including global built-ins)
$module: "math"Function named in that @use namespace
$css: truePlain CSS function value if no Sass function matches
$css: true + $moduleError — cannot combine
Missing Sass name, $css: falseThrows
vs get-mixin.

Functions use get-function + call. Mixins use meta.get-mixin + meta.apply.

SCSS Examples

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

Example 1 — Resolve a Module Function and Call It

Get math.abs, then invoke with meta.call.

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

.basic {
  width: meta.call(meta.get-function("abs", $module: "math"), -12px);
}

How It Works

  1. $module: "math" targets the namespace.
  2. get-function returns a function value.
  3. call runs it with -12px.
  4. Result is 12px.

Example 2 — Official Docs remove-where

Pass a local function value into a higher-order filter.

SCSS
@use "sass:list";
@use "sass:meta";
@use "sass:string";

/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition) {
  $new-list: ();
  $separator: list.separator($list);
  @each $element in $list {
    @if not meta.call($condition, $element) {
      $new-list: list.append($new-list, $element, $separator: $separator);
    }
  }
  @return $new-list;
}

$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;

.content {
  @function contains-helvetica($string) {
    @return string.index($string, "Helvetica");
  }
  font-family: remove-where($fonts, meta.get-function("contains-helvetica"));
}

How It Works

  1. Local function is defined inside .content.
  2. get-function captures it as a value.
  3. remove-where calls that value per font.
  4. Matches the official Sass docs CSS output.

Example 3 — Plain CSS Function with $css: true

Emit a CSS function reference when there is no Sass function of that name.

SCSS
@use "sass:meta";

.css-fn {
  filter: meta.call(meta.get-function("blur", $css: true), 4px);
}

How It Works

  1. blur is not a Sass built-in here.
  2. $css: true builds a CSS function value.
  3. call emits blur(4px).
  4. Do not also pass $module.

Example 4 — Guard with function-exists

Check first when the API might be missing.

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

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

How It Works

  1. exists answers yes/no safely.
  2. get-function only runs on the true path.
  3. call produces 8px.
  4. Avoids a hard error for optional APIs.

Example 5 — Functions vs Mixins

Use get-function for return values; get-mixin for CSS-emitting mixins.

SCSS
@use "sass:meta";

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

@mixin card($pad) {
  .card {
    padding: $pad;
  }
}

.demo {
  margin: meta.call(meta.get-function("gap"), 4px);
  @include meta.apply(meta.get-mixin("card"), 1rem);
}

How It Works

  1. get-function + call returns 8px.
  2. get-mixin + apply emits the card rule.
  3. Different member types need different APIs.
  4. Do not mix them up.

Edge Cases & Pitfalls

Most get-function bugs are forgetting $module, combining $css wrongly, or never calling the value.

module

Namespaced APIs need $module

get-function("abs") is not math.abs. Pass $module: "math".

css

Cannot mix $css and $module

Official docs: setting both is an error. Choose one mode.

invoke

Resolve ≠ call

You still need meta.call to run the returned value.

scope

Local functions need local scope

In the official sample, contains-helvetica is defined where get-function can see it.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
meta.get-function()Dart Sass via @use "sass:meta"
Global get-function()Legacy; prefer module form
Return typeFunction value (Sass or CSS when $css: true)
Invoke withmeta.call($function, $args...)

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns a function value for a name (and optional module).
  • Invoke with meta.call; use $css: true for plain CSS functions.
  • Pair with function-exists for optional APIs.
  • Mixin counterpart: meta.get-mixin + meta.apply.

One line: when you need a function value to pass around or call dynamically, use meta.get-function($name, $css: false, $module: null).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. meta.get-function("name") or with $module
3. meta.call($fn, $args...)
4. Use $css: true only for plain CSS functions
5. Prefer function-exists before optional lookups

Frequently Asked Questions

meta.get-function($name, $css: false, $module: null) returns a function value for the named function. You typically run that value with meta.call($fn, $args...).
When the function lives under a @use namespace. For example meta.get-function("abs", $module: "math") after @use "sass:math". The string must match that file’s namespace.
By default, a missing Sass function name throws. With $css: true, get-function returns a plain CSS function value instead—useful when you want to emit CSS like blur() as a function reference. It’s an error to combine $css: true with $module.
function-exists returns true/false. get-function returns the actual function value (or errors unless $css is true). Check with exists first for optional APIs.
Use meta.call($function, $args...). Passing a string name directly to call() is deprecated—get-function is the modern first step.
Yes. get-function($name, $css: false, $module: null) is the legacy global name. Prefer meta.get-function after @use "sass:meta".

Next: Sass meta.get-mixin()

Resolve a mixin name to a value you can include with meta.apply.

meta.get-mixin() →

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