Favorites

CSS <calc-keyword> Data Type

<calc-keyword>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <calc-keyword> data type is a math constant used inside calc() and other math functions: e, pi, infinity, -infinity or NaN.

☕
Enjoying this site?

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

Buy us a coffee

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

calc()
Demo Code
HTML Code
<div class="demo-element">calc()</div>
CSS Code
.demo-element {
	width: 200px;
	height: 60px;
	margin: 20px;
	display: grid;
	place-items: center;
	background: #4361ee;
	color: #fff;
	font-weight: bold;
	width: calc(pi * 50px);
}

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

<div class="wrap">
<h1>CSS &lt;calc-keyword&gt; examples</h1>
<div class="grid">
<div class="card">
<div class="stage"><div class="pill">Pill button</div></div>
<div class="label">border-radius: calc(infinity * 1px)</div>
</div>
<div class="card">
<div class="stage"><div class="square"></div></div>
<div class="label">rotate(calc(pi / 4 * 1rad))</div>
</div>
<div class="card">
<div class="stage"><div class="bar"></div></div>
<div class="label">width: calc(e * 30px)</div>
</div>
</div>
</div>
/* Demonstrates the  constants e, pi and infinity */
* { 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: 820px;
  margin: 0 auto;
}

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

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

.card {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  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: #506176;
  margin-top: 14px;
}

.stage {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* infinity: a pill shape that stays round at any size */
.pill {
  padding: 14px 32px;
  background: #7c3aed;
  color: #fff;
  font-weight: 700;
  border-radius: calc(infinity * 1px);
}

/* pi: rotate a quarter turn (pi / 2 radians) */
.square {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #06b6d4, #2563eb);
  border-radius: 8px;
  transform: rotate(calc(pi / 4 * 1rad));
}

/* e: width of e times 30px (about 81.5px) */
.bar {
  height: 24px;
  width: calc(e * 30px);
  background: #f59e0b;
  border-radius: 4px;
}
Open in editor

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.

This data type 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