Sass math.min()

Beginner
8 min read
Updated: Nov 2026
5 examples
Dart Sass 1.23+

Definition and Usage

math.min($number...) returns the lowest of one or more numbers. Arguments must have compatible units or all be unitless. Units on the winning value are kept. Load it with @use "sass:math" (Dart Sass 1.23+ for modules; global min() also exists).

Official samples.

math.min(1px, 4px) → 1px · math.min(50px, 30px, 100px) via list spread → 30px.

Compile-time minimum.

Sass writes a fixed number into CSS. For fluid values like min(10vw, 2rem), leave CSS min() in the stylesheet.

Prefer the module form.

Global min() still works for older stylesheets. New code should use math.min after @use "sass:math" so the helper clearly comes from the math module.

Syntax

SCSS
@use "sass:math";

math.min($number...); //=> number

math.min(1px, 4px); // 1px

$widths: 50px, 30px, 100px;
math.min($widths...); // 30px

math.min(3, 9, 1); // 1

// Global name (legacy)
min(1px, 4px); // 1px

// Module API — prefer math.min after @use "sass:math"

Pattern: collect comparable tokens → call math.min (optionally with list spread) → emit the winning length. Pair with math.max and math.clamp.

Units and Lists

How arguments behave:

CallResult
math.min(1px, 4px)1px
math.min($widths...) with 50px, 30px, 100px30px
math.min(3, 9, 1)1
math.min(-2px, -8px, -1px)-8px (most negative)
Incompatible units (e.g. px/em)Compile error
List spread.

Official docs show spreading a list with $widths... so you can store candidates in one variable.

SCSS Examples

Examples target Dart Sass with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Official Docs Sample

Pick the smaller of two lengths.

SCSS
@use "sass:math";

@debug math.min(1px, 4px); // 1px

.basic {
  --a: #{math.min(1px, 4px)};
}

How It Works

  1. Both args are px lengths.
  2. 1px is lower than 4px.
  3. Unit stays on the result.
  4. Matches the official Sass docs sample.

Example 2 — Official Docs Sample (List Spread)

Spread a list of candidates with ....

SCSS
@use "sass:math";

$widths: 50px, 30px, 100px;

@debug math.min($widths...); // 30px

.spread {
  --b: #{math.min($widths...)};
}

How It Works

  1. Store candidates in a list.
  2. Spread with $widths....
  3. Winner is 30px.
  4. Matches the official Sass docs sample.

Example 3 — Unitless Numbers

Works the same without units.

SCSS
@use "sass:math";

.unitless {
  --n: #{math.min(3, 9, 1)};
}

How It Works

  1. Three unitless values.
  2. Lowest is 1.
  3. Result stays unitless.
  4. Useful for counts and scale indexes.

Example 4 — Negative Lengths

“Lowest” means closest to -infinity, even among negatives.

SCSS
@use "sass:math";

.neg {
  --n: #{math.min(-2px, -8px, -1px)};
}

How It Works

  1. All values are negative px.
  2. -8px is the lowest.
  3. Not the smallest absolute magnitude.
  4. Use math.abs first if you need magnitude.

Example 5 — Design Tokens into CSS

Cap width and font-size tokens at a build-time ceiling.

SCSS
@use "sass:math";

$min: 12px;
$preferred: 18px;

.box {
  width: math.min($min, $preferred);
  font-size: math.min(0.875rem, 1rem);
}

How It Works

  1. Smaller values win when they are lower.
  2. Sass emits fixed lengths — no CSS min() left.
  3. Useful for build-time token caps.
  4. Keep CSS min() when a term needs vw/vh at runtime.

Edge Cases & Pitfalls

Most min bugs are incompatible units or expecting a live CSS function in the output.

units

Compatible units required

px with em fails. Check with math.compatible.

css

Sass vs CSS min()

Need viewport math? Leave CSS min() in the stylesheet instead of resolving it in Sass.

sign

Negatives use numeric order

math.min(-8px, -1px) is -8px, not the smaller absolute value.

clamp

Need both bounds?

Use math.clamp when a value must sit between a min and a max.

Sass Support

Prefer the module form with Dart Sass 1.23+.

APIStatus
math.min()Dart Sass 1.23+ via @use "sass:math"
Global min()Works for older stylesheets; prefer math.min
InputOne or more numbers: unitless or compatible units
LibSass / Ruby SassUse global min() if modules are unavailable

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns the lowest of one or more numbers.
  • Keeps units on the winning value.
  • Supports list spread with $list....
  • Compile-time — use CSS min() for fluid values.

One line: when several Sass numbers must collapse to the smallest, call math.min($number...).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Pass comparable numbers (or spread a list)
3. Expect the lowest value with its units
4. Prefer math.min over bare min() in new code
5. Use CSS min() when values must stay fluid

Frequently Asked Questions

math.min($number...) returns the lowest of one or more Sass numbers. For example math.min(1px, 4px) is 1px. Arguments need compatible units (or all be unitless).
Add @use "sass:math"; then call math.min(...) with one or more numbers. You can also spread a list: math.min($widths...).
Yes. The global min($number...) name still works for older stylesheets. New projects should prefer math.min() from sass:math so the helper clearly comes from the math module.
Same idea, different stage. Sass math.min() runs at compile time and writes a fixed number. CSS min() stays in the stylesheet and can mix lengths like min(10vw, 2rem) in the browser.
If the numbers cannot be compared (for example 10px and 2em), Sass raises a compile error. Keep arguments in a compatible unit family or all unitless. Check with math.compatible().
Yes. Put the values in a list and spread it with ... — for example math.min($widths...) where $widths is 50px, 30px, 100px.

Next: Sass math.percentage()

Convert a unitless decimal into a percentage.

math.percentage() →

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