Sass math.hypot()

Beginner
9 min read
Updated: Nov 2026
5 examples
Dart Sass 1.25+

Definition and Usage

math.hypot($number...) returns the length of the n-dimensional vector whose components are the given numbers. For two sides that is the classic hypotenuse √(a² + b²); for three it is √(a² + b² + c²), and so on. Arguments must all have compatible units or all be unitless. The result takes the unit of the first number. Load it with @use "sass:math" on Dart Sass 1.25+.

Official samples.

math.hypot(3, 4) → 5 · math.hypot(1in, 10cm, 50px) → 4.0952775683in.

Compile-time distance.

Sass writes a fixed length into CSS. For fluid viewport diagonals, compute in CSS or JavaScript instead.

Unit of the first argument wins.

Compatible absolutes convert, but the output unit follows the first component. Put the unit you want first, or check with math.compatible.

Syntax

SCSS
@use "sass:math";

math.hypot($number...); //=> number

math.hypot(3, 4); // 5

$lengths: 1in, 10cm, 50px;
math.hypot($lengths...); // 4.0952775683in

math.hypot(5px, 12px); // 13px
math.hypot(2, 3, 6);   // 7

// Module API — prefer math.hypot after @use "sass:math"

Pattern: collect component lengths → call math.hypot (optionally with list spread ...) → emit a diagonal or distance token. Related: math.sqrt, math.pow, math.abs.

Units and Dimensions

How arguments and units behave:

CallResult
math.hypot(3, 4)5 (2D hypotenuse)
math.hypot(5px, 12px)13px
math.hypot(2, 3, 6)7 (3D length)
math.hypot(10px)10px (1D ≈ abs for positive)
math.hypot(1in, 10cm, 50px)4.0952775683in (first unit)
Mixed incompatible unitsCompile error
Variadic + list spread.

Pass any number of components, or spread a list with $lengths... as in the official docs.

SCSS Examples

Examples target Dart Sass 1.25+ with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Official Docs Sample (3-4-5)

Classic Pythagorean hypotenuse.

SCSS
@use "sass:math";

@debug math.hypot(3, 4); // 5

.basic {
  --a: #{math.hypot(3, 4)};
}

How It Works

  1. Components are 3 and 4.
  2. Formula is √(9 + 16).
  3. Result is 5.
  4. Matches the official Sass docs sample.

Example 2 — Official Docs Sample (List Spread)

Compatible absolute lengths convert; first unit wins.

SCSS
@use "sass:math";

$lengths: 1in, 10cm, 50px;

@debug math.hypot($lengths...); // 4.0952775683in

.lengths {
  --b: #{math.hypot($lengths...)};
}

How It Works

  1. List spread passes three components.
  2. in, cm, px are compatible absolutes.
  3. Result unit follows the first value → in.
  4. Matches the official Sass docs sample.

Example 3 — Same-Unit Hypotenuse

Another 5-12-13 triangle in pixels.

SCSS
@use "sass:math";

.px {
  --two: #{math.hypot(5px, 12px)};
}

How It Works

  1. Both sides are px.
  2. √(25 + 144) → 13.
  3. Unit stays px on the result.
  4. Ready for CSS width/height tokens.

Example 4 — Three-Dimensional Length

More than two components still follow the same root-sum-square idea.

SCSS
@use "sass:math";

.three {
  --v: #{math.hypot(2, 3, 6)};
  --one: #{math.hypot(10px)};
}

How It Works

  1. √(4 + 9 + 36) → 7.
  2. One argument returns that component’s magnitude.
  3. Variadic API scales from 1D to nD.
  4. All unitless or all compatible units required.

Example 5 — Diagonal Box Size

Turn offset tokens into a compile-time diagonal width.

SCSS
@use "sass:math";

$dx: 30px;
$dy: 40px;

.box {
  width: math.hypot($dx, $dy);
}

How It Works

  1. Offsets are 30px and 40px.
  2. Hypotenuse is the familiar 3-4-5 scaled by 10.
  3. CSS sees 50px with no formula left.
  4. Useful for icon frames, rotated cards, and fixed diagonals.

Edge Cases & Pitfalls

Most hypot bugs are incompatible units or unexpected output units.

units

Compatible or all unitless

px with em fails. Check with math.compatible.

first

First argument sets the unit

math.hypot(1in, 10cm) returns inches, not centimeters.

stage

Compile time only

Cannot hypot live CSS custom properties or fluid vw values in Sass.

module

Module-only helper

Use math.hypot after @use "sass:math".

Sass Support

Prefer the module form with Dart Sass 1.25+.

APIStatus
math.hypot()Dart Sass 1.25+ via @use "sass:math"
InputOne or more numbers: unitless or compatible units
Result unitUnit of the first number
LibSass / Ruby SassNo modern sass:math hypot

Compile with the Dart Sass CLI.

Key Takeaways

  • Vector length — root-sum-square of the components.
  • Compatible units (or all unitless); first unit wins.
  • Supports list spread with $list....
  • Dart Sass 1.25+ via @use "sass:math".

One line: when several Sass lengths must become one distance, call math.hypot($number...).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Pass compatible components (or all unitless)
3. Put the desired result unit first
4. Spread lists with $lengths... when helpful
5. Expect a fixed CSS length at compile time

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.

Next: Sass math.is-unitless()

Return whether a Sass number has no units attached.

math.is-unitless() →

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.

8 people found this page helpful