Sass Function Values

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

Definition and Usage

In Sass a function is a value. Look one up with meta.get-function(), keep it in a variable, pass it to other functions, store it in a map—then run it later with meta.call().

This gives you higher-order functions: a helper that accepts another function as an argument, such as one that applies a transform to every item in a list.

Not CSS.

A function value only exists at compile time. You cannot write it into a property; meta.inspect() prints it as get-function("double") and meta.type-of() reports function.

Look up, then call.

meta.get-function("name") returns the value. meta.call($fn, $args...) invokes it, passing positional or keyword arguments just like a normal call.

Names are strings.

meta.get-function("double") takes the name of an existing function. A name that does not exist is a compile error, so check with meta.function-exists() when unsure.

Syntax

SCSS
@use "sass:meta";

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

$fn: meta.get-function("double");

meta.call($fn, 4px);                         // 8px
meta.get-function("abs", $module: "math");   // function from a @use'd module
meta.get-function("translate", $css: true);  // plain CSS function

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

Pattern: define a function → meta.get-function returns a value → pass or store it → meta.call runs it when needed.

Getting and Calling Function Values

Ways to obtain and use a function value:

GoalCode ideaResult
User-defined functionmeta.get-function("double")Function value
Function from a modulemeta.get-function("abs", $module: "math")Module function value
Plain CSS functionmeta.get-function("translate", $css: true)Calls produce translate(...) text
Run a function valuemeta.call($fn, 4px)The function result
Check the typemeta.type-of($fn)function
Check a name firstmeta.function-exists("double")true / false
Sibling values.

Mixins work the same way—see mixin values. Modules are values too—see module values.

SCSS Examples

Open View Compiled CSS to see the result of each call.

Example 1 — Get a Function and Call It

Store double() in a variable, then call it with meta.call().

SCSS
@use "sass:meta";

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

$fn: meta.get-function("double");

.demo {
  --result: #{meta.call($fn, 4px)};
  --type: #{meta.type-of($fn)};
  --inspect: #{meta.inspect($fn)};
}

How It Works

  1. Define double() as usual.
  2. meta.get-function("double") returns a function value stored in $fn.
  3. meta.call($fn, 4px) runs it and returns 8px.
  4. meta.type-of is function; meta.inspect prints the lookup form.

Example 2 — Pass a Function as an Argument

A reusable helper applies any function to every list item.

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

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

@function map-list($list, $fn) {
  $result: ();
  @each $item in $list {
    $result: list.append($result, meta.call($fn, $item), comma);
  }
  @return $result;
}

.grid {
  gap: map-list(1px 2px 3px, meta.get-function("double"));
}

How It Works

  1. map-list accepts any function value as $fn.
  2. @each walks the list; meta.call($fn, $item) transforms each item.
  3. list.append builds the result as a comma list.
  4. Swap the function and the same helper does something new.

Example 3 — Module Functions and Plain CSS Functions

Reach a built-in module function or a plain CSS function by name.

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

$abs: meta.get-function("abs", $module: "math");
$translate: meta.get-function("translate", $css: true);

.demo {
  length: meta.call($abs, -5px);
  transform: meta.call($translate, 10px);
}

How It Works

  1. $module: "math" matches the namespace from @use "sass:math".
  2. meta.call($abs, -5px) runs math.abs and returns 5px.
  3. $css: true looks up a plain CSS function instead of a Sass one.
  4. Calling it produces the text translate(10px).

Example 4 — Keep Functions in a Map

Build a small dispatch table keyed by name.

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

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

@function half($n) {
  @return math.div($n, 2);
}

$ops: (
  "double": meta.get-function("double"),
  "half": meta.get-function("half"),
);

.panel {
  width: meta.call(map.get($ops, "double"), 10px);
  height: meta.call(map.get($ops, "half"), 10px);
}

How It Works

  1. Each map value is a function value.
  2. map.get($ops, "double") fetches the one you want.
  3. meta.call runs it with the argument.
  4. Add an entry to extend the table without touching the callers.

Example 5 — Keyword Arguments and Checks

meta.call() forwards positional and named arguments.

SCSS
@use "sass:meta";

@function box($width, $scale: 1) {
  @return $width * $scale;
}

$fn: meta.get-function("box");

.demo {
  scaled: meta.call($fn, 2px, $scale: 3);
  default: meta.call($fn, 2px);
  exists: meta.function-exists("box");
  type: meta.type-of($fn);
}

How It Works

  1. meta.call($fn, 2px, $scale: 3) forwards the keyword argument.
  2. meta.call($fn, 2px) uses the default $scale: 1.
  3. function-exists("box") confirms the name before lookup.
  4. Same rules as a normal call—extra arguments are an error.

Edge Cases & Pitfalls

Most function-value bugs are wrong names, trying to print the value, or passing too many arguments.

name

Unknown names fail

meta.get-function("nope") is an error. Guard with meta.function-exists() when the name is dynamic.

print

A function cannot be a CSS value

Assigning meta.get-function(...) to a property fails because it is not valid CSS. Use meta.inspect() to debug it.

args

Argument rules still apply

meta.call($fn, 1, 2) on a one-argument function fails with an arity error, exactly like a direct call.

module

Module functions need the namespace

Use $module: "math" (the @use namespace), not the full sass:math URL.

Sass Support

Function values are part of the core Sass module system.

FeatureStatus
meta.get-function() / meta.call()Supported in Dart Sass
$module and $css argumentsSupported
Function values in maps and variablesSupported
LibSass / Ruby SassOlder, less complete support

Compile with the Dart Sass CLI.

Key Takeaways

  • Functions are values you can store and pass around.
  • meta.get-function looks one up; meta.call runs it.
  • Helpers can accept functions, giving you higher-order tools.
  • Function values never reach CSS—only their results do.

One line: look up a function with meta.get-function(), then run it later with meta.call().

Compile Notes

Practical checklist:

checklist.txt
1. Define the function with @function
2. $fn: meta.get-function("name")
3. Pass $fn to helpers or store it in a map
4. meta.call($fn, args...) to run it
5. Use meta.function-exists() for dynamic names

Frequently Asked Questions

A function value is a first-class value that refers to a function. You get one with meta.get-function() and run it with meta.call().
Use meta.call($fn, $args...). For example, meta.call($fn, 4px) runs the function and returns its result.
Yes. Pass the value from meta.get-function() to a helper function or mixin, then call it with meta.call() inside.
Use meta.get-function("abs", $module: "math") where the module name matches the @use namespace. Use $css: true for a plain CSS function.
No. A function value is not valid CSS. Use meta.inspect() to see it as get-function("name") while debugging.
meta.get-function() throws a compile error. Check with meta.function-exists() first when the name is not fixed.

Next: Sass Mixin Values

Store mixins in variables and include them with meta.apply().

Mixin Values →

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