CSS <calc-keyword> Data Type
The <calc-keyword> data type is a math constant used inside calc() and other math functions: e, pi, infinity, -infinity or NaN.
Description
The <calc-keyword> CSS data type represents a set of named constants that can be used inside CSS math functions such as calc(), min(), max() and clamp(). The constants are e, pi, infinity, -infinity and NaN. They let you write mathematical values directly in CSS instead of typing out long approximations such as 3.14159.
These keywords are only valid inside a math function. Writing width: pi; on its own is invalid, but rotate: calc(pi * 1rad); works. Each keyword is a plain <number>, so to use it with a property that expects a unit you must multiply it by a value with that unit, for example calc(infinity * 1px). The keywords are case-insensitive, so PI and Pi are also accepted.
pi is handy for geometry, such as working out the circumference of a circle for an SVG stroke animation, or converting radians. e is useful for exponential scales together with functions like pow() and log(). infinity is often used to say "as large as possible", for example to make a fully rounded pill shape or to place an element above everything else. The browser clamps infinite values to the largest value it supports. NaN mostly exists so that calculations that produce an undefined result have a defined value, and is rarely written by hand.
Examples:
/* Rotate by half a turn using pi radians */
.flip {
transform: rotate(calc(pi * 1rad));
}
/* Always-round pill shape, whatever the height */
.pill {
border-radius: calc(infinity * 1px);
}
/* Circumference of a circle with a 40px radius */
.ring {
stroke-dasharray: calc(2 * pi * 40px);
}
/* Put an overlay above everything else */
.overlay {
position: fixed;
z-index: calc(infinity);
}
Because the constants are evaluated by the browser, they can be combined with custom properties and other units in the same expression, keeping complex calculations readable.
Interactive Demo
Syntax
<calc-keyword> = e | pi | infinity | -infinity | NaN
Values
- eThe base of the natural logarithm, approximately 2.7182818284590452354.
- piThe ratio of a circle's circumference to its diameter, approximately 3.1415926535897932.
- infinityRepresents positive infinity. When used with a property, it is clamped to the largest value the browser supports.
- -infinityRepresents negative infinity. When used with a property, it is clamped to the smallest value the browser supports.
- NaNRepresents "Not a Number", the result of an undefined calculation such as 0 / 0.
Example
Browser Support
The following information will show you the current browser support for the CSS calc-keyword data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





