hypot() CSS Function
The hypot() function returns the square root of the sum of the squares of its arguments, the length of the diagonal of a right-angled triangle.
Description
The hypot() CSS function returns the square root of the sum of the squares of its arguments. In everyday terms, it calculates the length of the hypotenuse of a right-angled triangle: given the width and height of a box, hypot() gives the length of its diagonal. With more than two arguments it calculates the length of a vector in more dimensions.
All arguments must be of the same type, such as all lengths or all numbers, and the result has that same type. For example, hypot(3px, 4px) is 5px. This makes it useful for sizing elements that must span a diagonal, for circles that need to cover a whole rectangle, or for distances between two points stored in custom properties.
/* A line that stretches across the diagonal of a 300 x 160 box */
.diagonal {
width: hypot(300px, 160px); /* 340px */
transform: rotate(atan2(160px, 300px));
transform-origin: left center;
}
/* Distance between two points */
.connector {
--dx: 120px;
--dy: 90px;
width: hypot(var(--dx), var(--dy)); /* 150px */
}
hypot() is one of the exponential math functions, alongside pow(), sqrt(), log() and exp(). It works anywhere calc() does.
Interactive Demo
Syntax
hypot() = hypot( <calc-sum># )
Values
- <calc-sum>#One or more comma-separated calculations that all resolve to the same type, such as <length>, <number> or <percentage>. The result is the square root of the sum of their squares, in the same type.
Example
Browser Support
The following information will show you the current browser support for the CSS hypot() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





