math.hypot() is a distance helper in the sass:math module. It returns the length of an n-dimensional vector from its components. With two sides of a right triangle, that length is the hypotenuse. You will learn unit rules, Dart Sass 1.25+ notes, list spreading, and five compiled examples.
01
Concept
Vector length
02
Module
@use "sass:math"
03
2D case
√(a² + b²)
04
Units
First arg wins
05
Since
Dart Sass 1.25+
06
Practice
5 examples
Concept
What Is math.hypot()?
Imagine each argument as one side of a multi-dimensional arrow. math.hypot() returns how long that arrow is. For two numbers a and b, it is the familiar Pythagorean result:
3² + 4² = 25, and the square root is 5. With px, the result is 5px.
Example 2 — Spread Compatible Lengths
Official-style list with mixed absolute units; result unit follows the first item.
styles.scss
@use "sass:math";
$lengths: 1in, 10cm, 50px;
@debug math.hypot($lengths...); // ~4.0952775683in
.box {
// use the computed distance as a max size
max-width: math.hypot($lengths...);
}
📤 Compiled CSS:
.box {
max-width: 4.0952775683in;
}
How It Works
Sass converts cm and px into the same absolute space as 1in, then returns the vector length in inches.
📈 Practical Patterns
Diagonals, 2D offsets, and three-component lengths.
Example 3 — Card Diagonal from Width and Height
Size a decorative diagonal stroke from known card dimensions.
Incompatible units — px with em fails; keep a compatible family.
Surprised by output unit — the first argument decides the result unit.
Expecting fluid layout math — hypot cannot resolve live viewport or measured element sizes.
Old Dart Sass — need 1.25+; LibSass lacks the module API.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:math" and math.hypot() in new SCSS
Keep arguments in a compatible unit family
Put the preferred result unit first in the argument list
Spread lists with $list... for generated components
Prefer Dart Sass 1.25+
❌ Don’t
Expect the browser to re-evaluate math.hypot
Mix relative and absolute units carelessly
Use Sass hypot for DOM-measured diagonals (use JS instead)
Hand-roll √(a²+b²) when hypot is available
Rely on LibSass for sass:math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about math.hypot()
Compile-time vector length—first unit wins.
5
Core concepts
📝01
Call
math.hypot(...)
API
📦02
Module
sass:math
@use
📏03
2D
√(a²+b²)
Hypot
🎯04
Unit
first arg
Rule
⚡05
Since
Dart Sass 1.25+
Tooling
❓ Frequently Asked Questions
math.hypot($number...) returns the length of the n-dimensional vector whose components are the given numbers. For two values it is the hypotenuse: square root of a² + b². Example: math.hypot(3, 4) is 5.
Add @use "sass:math"; then call math.hypot(...) with one or more numbers. You can spread a list: math.hypot($lengths...). Requires Dart Sass 1.25+.
Arguments must all have compatible units or all be unitless. The result uses the unit of the first number. Example: math.hypot(1in, 10cm, 50px) returns a value in inches.
Official docs expose this as math.hypot() on sass:math. Prefer the module form with @use "sass:math".
math.abs() is one-dimensional distance from zero. math.hypot() combines several components into one length—like going from 1D absolute value to multi-dimensional distance.
Yes, when the side lengths are known at compile time. For viewport-based diagonals, compute in CSS or JavaScript instead—Sass hypot cannot use fluid vw values the same way.
Did you know?
Official Sass docs place math.hypot under Distance Functions next to math.abs. Absolute value asks “how far from zero on a line?” Hypot asks “how far from the origin in many directions?”
math.hypot() turns one or more known components into a single length at compile time. Keep units compatible, put the preferred result unit first, and use runtime tools when the sides of your triangle are measured in the browser.