Sass math.min() Function

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

What You’ll Learn

math.min() is a bounding helper in the sass:math module. It returns the lowest of one or more numbers and keeps compatible CSS units. You will learn module loading, list spreading with ..., how it differs from CSS min(), and five compiled examples.

01

Concept

Lowest value

02

Module

@use "sass:math"

03

Args

One or more numbers

04

Spread

$list...

05

Vs CSS

min()

06

Practice

5 examples

What Is math.min()?

math.min() compares its arguments and returns the smallest one. That is useful when several tokens or calculations compete and you want the tightest value baked into CSS.

  • math.min(1px, 4px)1px
  • math.min(50px, 30px, 100px)30px
  • math.min($widths...) → lowest item in the list

Pair it with math.max() when you need the largest value, or with math.clamp() when you need both a floor and a ceiling around one preferred number.

💡
Beginner tip

Browsers never see math.min. Dart Sass evaluates it and writes only the winning number into your .css file.

📝 Syntax

Load the math module, then pass one or more numbers:

styles.scss
@use "sass:math";

math.min($number...)
// also: math.min($list...)

Parameters

ParameterTypeRequiredDescription
$number...Number(s)YesOne or more Sass numbers to compare. All must have compatible units, or all be unitless. Spread a list with $list....

Return value

TypeSituationResult
NumberTwo or more comparable valuesThe lowest argument (unit kept)
NumberSingle argumentThat same number
ErrorIncompatible unitsCompile fails (cannot compare)

📦 Loading sass:math

styles.scss
// Recommended — namespaced
@use "sass:math";
$w: math.min(12px, 24px);

// Optional — bring members into the current namespace
@use "sass:math" as *;
$w: min(12px, 24px);

// Optional — custom namespace
@use "sass:math" as m;
$w: m.min(12px, 24px);
⚠️
Put @use first

Keep @use "sass:math"; near the top of the file. Do not confuse Sass math.min with CSS min() left in the output stylesheet.

📏 How Units Work

Arguments must be comparable. Compatible absolute lengths can mix; relative vs absolute often cannot.

CallResultNotes
math.min(1px, 4px)1pxSame unit
math.min(50px, 30px, 100px)30pxMany arguments
math.min(1cm, 8mm)8mm (smaller than 1cm)Compatible absolute lengths
math.min(2, 9, -1)-1Unitless
math.min(10px, 2em)Error: incompatible units

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a plain number unless you wrote CSS min() yourself.

Implementation@use "sass:math"Global min()
Dart Sass (1.23+)Yes — preferredYes
LibSassNo built-in modulesYes (legacy)
Ruby SassNo built-in modulesYes (legacy)

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Lowest of twomath.min(1px, 4px)1px
Lowest of manymath.min(50px, 30px, 100px)
Spread a listmath.min($widths...)
Legacy global callmin($a, $b)
Debug while learning@debug math.min(1px, 4px);

📋 min vs max vs clamp

HelperReturnsTypical use
math.min(...)Lowest argumentPick the smallest width, gap, or token
math.max(...)Highest argumentPick the largest bound
math.clamp(min, n, max)Value inside a rangeForce one number between two bounds

📋 Sass math.min() vs CSS min()

Sass math.min()CSS min()
When it runsCompile time (Dart Sass)In the browser
Appears in CSS output?No — only the resultYes — as min(...)
Viewport / fluid values?No (values must be known)Yes (e.g. min(100%, 32rem))
Best forFixed tokens & SCSS formulasResponsive caps at runtime

If any candidate depends on the viewport or container, use CSS min(). If every candidate is a known Sass number, use math.min() and ship one length.

Examples Gallery

Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official-style min calls and list spreading.

Example 1 — Basic math.min()

Compare two lengths and keep the smaller one.

styles.scss
@use "sass:math";

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

.box {
  border-width: math.min(1px, 4px);
}

How It Works

Sass compares 1px and 4px, keeps 1px, and writes that into CSS.

Example 2 — Spread a List with ...

Pass every item in a list as a separate argument.

styles.scss
@use "sass:math";

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

.hero {
  min-width: math.min($widths...);
}

How It Works

$widths... expands to 50px, 30px, 100px. The smallest is 30px.

📈 Practical Patterns

Caps, gaps, and pairing with max.

Example 3 — Cap a Computed Size

When a computed size might grow too large, take the min with a ceiling token.

styles.scss
@use "sass:math";

$computed: 96px;
$ceiling: 64px;

.button {
  max-width: math.min($computed, $ceiling);
}

How It Works

64px wins over 96px, so the button never exceeds the design ceiling. (For a full min/preferred/max corridor, prefer math.clamp().)

Example 4 — Smallest Gap from a Scale

Pick the tightest spacing token for a dense component.

styles.scss
@use "sass:math";

$space-sm: 8px;
$space-md: 16px;
$space-lg: 24px;

.toolbar {
  gap: math.min($space-sm, $space-md, $space-lg);
}

How It Works

Among 8px, 16px, and 24px, Sass keeps 8px.

Example 5 — Min and Max Side by Side

Use both helpers when a layout needs the smallest and largest of the same set.

styles.scss
@use "sass:math";

$sizes: 12px, 40px, 24px;

.card {
  padding: math.min($sizes...);
  margin-block: math.max($sizes...);
}

How It Works

The same list yields 12px for min and 40px for max—compact padding, generous outer margin.

🚀 Real-World Use Cases

  • Token selection — pick the smallest spacing, radius, or type size from a set.
  • Maximum capsmath.min($computed, $ceiling) so sizes never grow too large.
  • Map / list pipelines — spread generated lists of lengths and take the trough.
  • Dense UI — choose the tightest gap that still matches your scale.
  • Paired with max — report both ends of a scale for padding vs margin.
  • Fixed vs fluid — use Sass min for known numbers; CSS min for viewport math.

🧠 How Compilation Works

1

Write SCSS

Call math.min(...) or math.min($list...) after @use.

Source
2

Check units

Sass verifies the arguments can be compared safely.

Validate
3

Pick the lowest

The smallest comparable number wins; its unit stays attached.

Min
4

Plain CSS ships

The browser only receives the final winning number.

⚠️ Common Pitfalls

  • Forgetting @usemath.min needs sass:math loaded.
  • Incompatible unitspx vs em fails; keep a shared family.
  • Expecting fluid CSS — Sass min cannot mix vw the way CSS min can.
  • Confusing with clamp — min picks a winner among candidates; clamp bounds one preferred value.
  • LibSass pipelines — prefer Dart Sass for the module API.

💡 Best Practices

✅ Do

  • Use @use "sass:math" and math.min() in new SCSS
  • Keep arguments in a compatible unit family
  • Spread lists with $list... for generated values
  • Use CSS min() when viewport math is required
  • Prefer Dart Sass for built-in modules

❌ Don’t

  • Expect the browser to re-evaluate math.min
  • Mix relative and absolute units carelessly
  • Replace CSS fluid min() with Sass when %/vw is involved
  • Use min when you really need a min–max corridor (clamp)
  • Rely on LibSass for sass:math

Key Takeaways

Knowledge Unlocked

Five things to remember about math.min()

Compile-time lowest value—compatible units required.

5
Core concepts
📦 02

Module

sass:math

@use
03

Result

lowest

Min
📏 04

Units

compatible

Rule
05

When

compile time

Sass

❓ 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 two 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.
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.
Yes. Put the values in a list and spread it with ... — for example math.min($widths...) where $widths is 50px, 30px, 100px.
Did you know?

Official Sass docs place math.min under Bounding Functions next to max, clamp, ceil, floor, and round. Min and max are mirrors: one returns the trough, the other the peak.

Conclusion

math.min() picks the lowest comparable number at compile time. Spread lists when you need to, keep units compatible, and switch to CSS min() when the candidates must stay fluid with the viewport.

Continue with math.percentage(), math.max(), or math.clamp().

More Sass Math

Continue with decimal-to-percent conversion in the math module.

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.

5 people found this page helpful