math.max() is a bounding helper in the sass:math module. It returns the highest of one or more numbers and keeps compatible CSS units. You will learn module loading, list spreading with ..., how it differs from CSS max(), and five compiled examples.
01
Concept
Highest value
02
Module
@use "sass:math"
03
Args
One or more numbers
04
Spread
$list...
05
Vs CSS
max()
06
Practice
5 examples
Concept
What Is math.max()?
math.max() compares its arguments and returns the largest one. That is useful when several tokens or calculations compete and you want the winner baked into CSS.
math.max(1px, 4px) → 4px
math.max(50px, 30px, 100px) → 100px
math.max($widths...) → highest item in the list
Pair it with math.min() when you need the smallest value, or with math.clamp() when you need both a floor and a ceiling around one preferred number.
💡
Beginner tip
Browsers never see math.max. Dart Sass evaluates it and writes only the winning number into your .css file.
Foundation
📝 Syntax
Load the math module, then pass one or more numbers:
Incompatible units — px vs em fails; keep a shared family.
Expecting fluid CSS — Sass max cannot mix vw the way CSS max can.
Confusing with clamp — max picks a winner among candidates; clamp bounds one preferred value.
LibSass pipelines — prefer Dart Sass for the module API.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:math" and math.max() in new SCSS
Keep arguments in a compatible unit family
Spread lists with $list... for generated values
Use CSS max() when viewport math is required
Prefer Dart Sass for built-in modules
❌ Don’t
Expect the browser to re-evaluate math.max
Mix relative and absolute units carelessly
Replace CSS fluid max() with Sass when vw is involved
Use max when you really need a min–max corridor (clamp)
Rely on LibSass for sass:math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about math.max()
Compile-time highest value—compatible units required.
5
Core concepts
📝01
Call
math.max(...)
API
📦02
Module
sass:math
@use
▲03
Result
highest
Max
📏04
Units
compatible
Rule
⚡05
When
compile time
Sass
❓ Frequently Asked Questions
math.max($number...) returns the highest of one or more Sass numbers. For example math.max(1px, 4px) is 4px. Arguments need compatible units (or all be unitless).
Add @use "sass:math"; then call math.max(...) with two or more numbers. You can also spread a list: math.max($widths...).
Yes. The global max($number...) name still works for older stylesheets. New projects should prefer math.max() from sass:math.
Same idea, different stage. Sass math.max() runs at compile time and writes a fixed number. CSS max() stays in the stylesheet and can mix lengths like max(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.max($widths...) where $widths is 50px, 30px, 100px.
Did you know?
Official Sass docs place math.max under Bounding Functions next to min, clamp, ceil, floor, and round. Max and min are the simplest bounds: one winner from a set of candidates.
math.max() picks the highest comparable number at compile time. Spread lists when you need to, keep units compatible, and switch to CSS max() when the candidates must stay fluid with the viewport.