Sass Special Functions

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

Definition and Usage

Most CSS functions are plain Sass function calls: Sass evaluates the arguments and writes the call back out as CSS. A small group of functions needs special parsing because their arguments are not ordinary SassScript—for example an unquoted url(...).

These special functions return unquoted strings (except calculations, which are their own value type). Interpolation with #{} still works inside them.

Modern math lives elsewhere.

calc(), clamp(), min(), and max() are now first-class calculations. See Sass calculations instead of treating them as legacy special functions.

Pass-through functions.

var() and env() are not evaluated by Sass at compile time. They are written to the CSS so the browser resolves them.

Legacy IE helpers.

expression() and progid:... exist only for very old Internet Explorer. Sass keeps them working but you should not use them in new code.

Syntax Overview

SCSS
$cdn: "https://cdn.example.com";
$gap: 8px;

.hero {
  background: url(#{$cdn}/hero.png);       // unquoted url + interpolation
  background-image: element(#preview);       // element() passes through
  padding: var(--gap, #{$gap});               // var() fallback uses SassScript
  margin-top: env(safe-area-inset-top, 20px);
  width: min(100%, 600px);                    // calculation (see calculations)
}

Pattern: write the CSS function as usual → use #{} to inject Sass values → leave var() / env() for the browser to resolve.

Special Function Guide

What Sass does with each function:

FunctionWhat Sass doesNotes
url()Parses an unquoted URL as an unquoted stringUse #{} to inject variables; quoted URLs are ordinary strings
element()Passes through (also -moz-element())Browser-specific background source
expression()Passes through as an unquoted stringLegacy IE only
progid:…Passes through as an unquoted stringLegacy IE filters
var() / env()Evaluates arguments, writes the call back to CSSFallback values may use SassScript
calc() / clamp() / min() / max()Parsed as calculationsSee calculations
Compile time vs run time.

Sass values like math.max() run at compile time. CSS functions like max() or var() are resolved by the browser (or simplified by Sass when every argument is a compatible number).

SCSS Examples

Open View Compiled CSS to see exactly what Sass writes for each special function.

Example 1 — url() with Interpolation

Unquoted URLs are parsed specially; interpolate Sass values into them.

SCSS
$cdn: "https://cdn.example.com";

.hero {
  background: url(#{$cdn}/hero.png);
}

.logo {
  background: url("logo.svg");
}

.icon {
  background: url(img/icon.png);
}

.remote {
  background: url($cdn);
}

How It Works

  1. url(#{$cdn}/hero.png) interpolates the variable and stays unquoted.
  2. url("logo.svg") is a normal quoted string and compiles unchanged.
  3. url(img/icon.png) is an unquoted URL kept as written.
  4. url($cdn) evaluates the variable, so Sass writes it as a quoted string.

Example 2 — element() Passes Through

Use the CSS element() function and its vendor-prefixed form.

SCSS
.mirror {
  background: element(#preview);
  background: -moz-element(#preview);
}

How It Works

  1. element(#preview) contains a selector-like argument that is not SassScript.
  2. Sass keeps it as written in the output.
  3. Vendor prefixes such as -moz-element() follow the same rule.
  4. Browser support is separate from Sass—check before shipping.

Example 3 — expression() and progid: Filters

Legacy Internet Explorer helpers are preserved as written.

SCSS
.old-ie {
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#80000000');
  width: expression(document.body.clientWidth > 800 ? "800px" : "auto");
}

How It Works

  1. progid: values are not valid SassScript, so Sass copies them through.
  2. expression() keeps its JavaScript-like body unchanged.
  3. Both are legacy—modern browsers ignore them.
  4. Prefer color.ie-hex-str() only if you must target old IE filters.

Example 4 — var() and env() Fallbacks

Sass evaluates fallback arguments and leaves the call for the browser.

SCSS
$fallback: 8px;

:root {
  --gap: 8px;
}

.card {
  padding: var(--gap, #{$fallback});
  margin-top: env(safe-area-inset-top, 20px);
  border-width: var(--border, $fallback);
}

How It Works

  1. --gap is declared as a normal CSS custom property.
  2. var(--gap, #{$fallback}) keeps var() and fills the fallback from Sass.
  3. env(...) is written through so the browser resolves safe-area values.
  4. A plain $fallback argument is evaluated too, so it also becomes 8px.

Example 5 — min(), max(), and calc() Hand Off to Calculations

When every argument is compatible, Sass simplifies; otherwise it keeps the CSS function.

SCSS
$a: 10px;

.box {
  width: min(100%, 600px);
  padding: max($a, 5vw);
  height: max(10px, 5px);
  gap: calc(10px + 2px);
  margin: calc(100% - 20px);
}

How It Works

  1. min(100%, 600px) cannot be simplified (different units), so it stays as CSS.
  2. max($a, 5vw) substitutes $a and stays as a calculation.
  3. max(10px, 5px) and calc(10px + 2px) simplify to plain numbers.
  4. Read Sass calculations for the full rules.

Edge Cases & Pitfalls

Most special-function problems are quoting, interpolation, or expecting Sass to compute browser-time values.

quotes

url() quoting changes the output

An unquoted url(...) stays unquoted, but url($var) evaluates the variable and writes it as a quoted string. Interpolate with #{} when you need the unquoted form.

browser

var() and env() are not computed by Sass

Sass cannot know custom property or environment values. Use Sass variables when the value is known at compile time.

units

Mixed units stay as CSS functions

min(100%, 600px) cannot be reduced because % and px are not comparable at compile time.

legacy

expression() is legacy

Sass passes it through, but modern browsers ignore it. Do not rely on it.

Sass Support

Special-function parsing is part of core Sass; calculations require a modern Dart Sass.

FeatureStatus
url(), element(), expression(), progid:Supported (passed through)
var() / env() fallbacksSupported (evaluated args, call preserved)
calc() / clamp() / min() / max() as calculationsDart Sass 1.40+ (see calculations)
LibSass / Ruby SassLegacy special-function handling only

Compile with the Dart Sass CLI.

Key Takeaways

  • Special functions have arguments that are not normal SassScript.
  • url(), element(), progid:, expression() pass through as unquoted strings.
  • var() and env() stay in the CSS for the browser to resolve.
  • calc(), clamp(), min(), max() belong to calculations.

One line: let Sass pass special CSS functions through, and use #{} when you need to inject Sass values.

Compile Notes

Practical checklist:

checklist.txt
1. Use #{$var} inside unquoted url(...)
2. Expect var() / env() to stay in the CSS
3. Do not use expression() or progid: in new code
4. Use calculations for calc / clamp / min / max
5. Check the compiled CSS when mixing units

Frequently Asked Questions

They are CSS functions whose arguments cannot be parsed as normal SassScript, such as url(), element(), expression(), and progid:. Sass passes them through as unquoted strings.
Yes. Use interpolation, for example url(#{$cdn}/hero.png). A quoted url("...") is an ordinary string.
No. Sass writes var() and env() to the CSS so the browser resolves them. Fallback arguments are evaluated as SassScript first.
They used to be treated as special strings. In current Dart Sass they are first-class calculations that can be simplified. See the calculations page.
No. They only target very old Internet Explorer. Sass preserves them but modern browsers ignore them.
Because url($var) is evaluated as an ordinary function call and the string value is quoted. Use url(#{$var}) when you want unquoted output.

Next: Sass Property Declarations

Write CSS properties inside Sass rules, including nested names.

Properties →

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