CSS sqrt() Function

The sqrt() function is a CSS math function that calculates the square root of a number.

A square root is simply the value that, when multiplied by itself, gives you the original number. When you use the sqrt() function in CSS, you provide it with a number, and it returns the square root as a unitless value.

For example:

While you might use the hypot() function to find diagonal distances, sqrt() is particularly useful for scaling elements proportionally by their area. If you double the width and height of a circle, you actually make its total area four times larger. If you want a circle to have exactly twice the visual weight (area) of another, you need to scale its dimensions by the square root of 2.

Here's an example demonstrating this concept. We have a base circle, and we want the second circle to be exactly twice as large in total area. By using sqrt(2) as our multiplier, we get a perfectly proportioned shape:

View Output Full Screen Preview

How It Works

The sqrt() function takes a single calculation as its argument. This argument must resolve to a unitless number that is greater than or equal to zero. If you try to pass a negative number (like sqrt(-4)), the result is NaN (Not a Number), and the CSS rule will be ignored.

Because the function returns a unitless number, you will usually need to multiply it by a length unit (like px or rem) inside a calc() function to apply it to sizing properties.

Official Syntax

The official syntax of the sqrt() function is as follows:

Possible Values

As indicated in the official syntax, the sqrt() function accepts the following value:

calc-sum

A mathematical calculation that resolves to a positive, unitless number (or zero). The function evaluates this input and returns its square root.

CSS Specifications

Browser Support

The following table provided by Caniuse.com shows the level of browser support for this feature.