Favorites

sqrt() CSS Function

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

The sqrt() function returns the square root of a number, such as sqrt(16), which is 4.

☕
Enjoying this site?

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

Buy us a coffee

Description

The sqrt() CSS function returns the square root of a number: the value that, multiplied by itself, gives the argument. For example, sqrt(16) is 4. The argument must be a plain <number> and the result is also a number, so you multiply it by a unit when you need a length. Negative numbers return NaN.

A practical use is sizing shapes by area rather than by width. If you want one square to have twice the area of another, its side must be sqrt(2) times as long, not twice as long. The same idea applies to circles in charts and bubble graphs, where the area should represent the data value so large values are not visually exaggerated.

/* Squares whose areas are 1x, 2x and 4x a base square */
.sq-1 { width: calc(sqrt(1) * 60px); aspect-ratio: 1; }
.sq-2 { width: calc(sqrt(2) * 60px); aspect-ratio: 1; }  /* about 84.9px */
.sq-4 { width: calc(sqrt(4) * 60px); aspect-ratio: 1; }  /* 120px */

/* Bubble chart where area matches the value */
.bubble {
  width: calc(sqrt(var(--value)) * 10px);
}

sqrt() is equivalent to pow(x, 0.5) and belongs to the exponential function family with hypot(), log() and exp().

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: calc(sqrt(4) * 50px);
}

Syntax

sqrt() = sqrt( <calc-sum> )

Values

  • <calc-sum>A calculation resolving to a <number>. The function returns its square root as a <number>.

Example

<div class="wrap">
<h1>CSS sqrt() examples</h1>
<div class="card row">
<div class="sq" style="--area: 1">1x</div>
<div class="sq" style="--area: 2">2x</div>
<div class="sq" style="--area: 4">4x</div>
<div class="sq" style="--area: 6">6x</div>
</div>
<p class="note">Each side is calc(sqrt(var(--area)) * 50px), so the area grows by the number shown.</p>
</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;
}

/* sqrt() examples */
.row {
display: flex;
align-items: flex-end;
gap: 24px;
}

.sq {
width: calc(sqrt(var(--area)) * 50px);
aspect-ratio: 1;
border-radius: 6px;
background: linear-gradient(135deg, #7c3aed, #2563eb);
color: #fff;
font-size: 12px;
font-weight: 700;
display: grid;
place-items: center;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS sqrt() 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