math.abs($number) returns the absolute value of $number. If $number is negative, this returns -$number; if positive, it returns $number as-is. Load it with @use "sass:math" on Dart Sass 1.23+. Global abs() still works.
Official samples.
math.abs(10px) → 10px. math.abs(-10px) → 10px.
Units are kept.
Only the sign changes. math.abs(-1.25rem) is 1.25rem; percentages and unitless numbers work the same way.
Compile-time result.
Sass resolves math.abs while compiling. The CSS file gets a plain positive number—not a live abs() call (unless you write CSS abs() yourself).
Returns the magnitude of a number; negatives become positive.
Keeps CSS units such as px, rem, and %.
Resolved at compile time into a plain CSS number.
Prefer math.abs after @use "sass:math".
One line: when a Sass number must be non-negative in CSS, call math.abs($number).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Call math.abs on signed lengths / deltas
3. Expect units to stay on the result
4. Use CSS abs() only when you need runtime behavior
5. Prefer math.abs over global abs() in new code
Frequently Asked Questions
math.abs($number) returns the absolute value of a Sass number. If $number is negative, it returns -$number; if positive, it returns $number as-is. Units such as px, rem, and % are kept.
Add @use "sass:math"; at the top of your SCSS file, then call math.abs($number). Example: math.abs(-10px) compiles to 10px.
Yes. The global abs($number) name still works for older stylesheets. New projects should prefer math.abs() so the helper clearly comes from sass:math.
No. math.abs(-24px) is 24px. Only the sign changes. Unitless inputs stay unitless.
Same idea, different stage. Sass math.abs() runs when you compile SCSS. CSS abs() runs in the browser. Use Sass when the value must be fixed in the output CSS.
Built-in modules with @use need Dart Sass 1.23+. LibSass and Ruby Sass do not load sass:math the same way—use the global abs() name there if you must.