math.max($number...) returns the highest 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 max() also exists).
Official samples.
math.max(1px, 4px) → 4px · math.max(50px, 30px, 100px) via list spread → 100px.
Compile-time maximum.
Sass writes a fixed number into CSS. For fluid values like max(10vw, 2rem), leave CSS max() in the stylesheet.
Prefer the module form.
Global max() still works for older stylesheets. New code should use math.max after @use "sass:math" so the helper clearly comes from the math module.
Syntax
Syntax
SCSS
@use "sass:math";
math.max($number...); //=> number
math.max(1px, 4px); // 4px
$widths: 50px, 30px, 100px;
math.max($widths...); // 100px
math.max(3, 9, 1); // 9
// Global name (legacy)
max(1px, 4px); // 4px
// Module API — prefer math.max after @use "sass:math"
Pattern: collect comparable tokens → call math.max (optionally with list spread) → emit the winning length. Pair with math.min and math.clamp.
Reference
Units and Lists
How arguments behave:
Call
Result
math.max(1px, 4px)
4px
math.max($widths...) with 50px, 30px, 100px
100px
math.max(3, 9, 1)
9
math.max(-2px, -8px, -1px)
-1px (least 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.
One line: when several Sass numbers must collapse to the largest, call math.max($number...).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Pass comparable numbers (or spread a list)
3. Expect the highest value with its units
4. Prefer math.max over bare max() in new code
5. Use CSS max() when values must stay fluid
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 one 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 so the helper clearly comes from the math module.
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. Check with math.compatible().
Yes. Put the values in a list and spread it with ... — for example math.max($widths...) where $widths is 50px, 30px, 100px.