Favorites

hypot() CSS Function

hypot()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

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.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

050px100px150px200px250px
Demo Code
HTML Code
<div class="demo-track">
	<div class="demo-element"></div>
</div>
<div class="demo-scale"><span>0</span><span>50px</span><span>100px</span><span>150px</span><span>200px</span><span>250px</span></div>
CSS Code
.demo-track {
	width: 300px;
	height: 36px;
	background: #f4f4f4 repeating-linear-gradient(90deg, #b0b0b0 0 1px, transparent 1px 50px);
	outline: 1px solid #c5c5c5;
}
.demo-scale {
	display: grid;
	grid-template-columns: repeat(6, 50px);
	width: 300px;
	font-size: 11px;
	color: #666;
}
.demo-element {
	height: 100%;
	background: linear-gradient(90deg, #f72585, #b5179e);
	width: hypot(-100px);
}

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

<div class="wrap">
<h1>CSS hypot() examples</h1>
<div class="grid">
<div class="card">
<div class="box"><div class="line"></div></div>
<div class="label">width: hypot(240px, 140px) /* about 277.8px */</div>
</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* hypot() examples */
.box {
position: relative;
width: 240px;
height: 140px;
margin: 0 auto;
border: 2px dashed #94a3b8;
border-radius: 4px;
}

/* the diagonal is exactly as long as hypot(240px, 140px) */
.line {
position: absolute;
left: 0;
top: 0;
height: 4px;
width: hypot(240px, 140px);
background: #dc2626;
border-radius: 2px;
transform-origin: left center;
transform: rotate(atan2(140px, 240px));
}
Open in editor

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee