Favorites

calc-size() CSS Function

calc-size()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 21st November 2026

The calc-size() function does calculations with intrinsic sizes such as auto and fit-content, and makes it possible to animate to height: auto.

☕
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-size() CSS function lets you perform calculations on intrinsic size keywords such as auto, min-content, max-content and fit-content, which calc() cannot use. Its most important benefit is that it makes these keywords animatable: for the first time, you can transition an element's height from 0 to its natural auto height, which is exactly what accordions, disclosure widgets and expanding menus need.

The first argument is the basis, usually a size keyword. The optional second argument is a calculation in which the keyword size stands for the resolved size of that basis. For example, calc-size(auto, size + 20px) means "the auto height plus 20px", and calc-size(max-content, size * 0.5) means "half the max-content width". If the second argument is left out, the result is simply the basis size. It can be used in sizing properties such as width, height, min-height, max-width and flex-basis.

/* Smoothly expand a panel to its natural height */
.panel {
  height: 0;
  overflow: clip;
  transition: height 0.4s ease;
}

.panel.open {
  height: calc-size(auto, size);
}

/* Natural width plus some extra room */
.badge {
  width: calc-size(fit-content, size + 2rem);
}

An alternative is the interpolate-size: allow-keywords property on :root, which allows transitions to and from size keywords throughout the page. calc-size() is currently supported only in Chromium-based browsers, so treat the animation as an enhancement.

Interactive Demo

The box size is calculated from its content size.
Demo Code
HTML Code
<div class="demo-element">The box size is calculated from its content size.</div>
CSS Code
.demo-element {
	width: 240px;
	padding: 8px 12px;
	box-sizing: border-box;
	background: #e7ecff;
	border: 2px solid #4361ee;
	font-size: 15px;
	overflow: hidden;
	height: calc-size(auto, size);
}

Syntax

calc-size() = calc-size( <calc-size-basis>, <calc-sum>? )

<calc-size-basis> = <size-keyword> | <calc-size()> | any | <calc-sum>

Values

  • <calc-size-basis>The size to calculate with: an intrinsic keyword such as auto, min-content, max-content, fit-content or stretch, another calc-size(), the keyword any, or a calculation.
  • <calc-sum>Optional. A calculation in which the keyword size represents the resolved size of the basis, for example size + 20px or size * 0.5. If omitted, the result is the basis size itself.

Example

<div class="wrap">
<h1>CSS calc-size() examples</h1>
<div class="card accordion">
<button class="toggle">Hover or focus to expand</button>
<div class="panel">
<p>This panel animates from height: 0 to height: calc-size(auto, size), so it grows to fit its content however long the text is. Without calc-size(), a transition to auto would jump instantly.</p>
</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;
}

/* calc-size() examples */
.accordion {
max-width: 480px;
}

.toggle {
display: block;
width: 100%;
padding: 12px 16px;
border: 0;
border-radius: 10px;
background: #2563eb;
color: #fff;
font: inherit;
font-weight: 600;
text-align: left;
cursor: pointer;
}

.panel {
height: 0;
overflow: clip;
transition: height 0.45s ease;
}

/* Expand to the natural height on hover or keyboard focus */
.accordion:hover .panel,
.accordion:focus-within .panel {
height: calc-size(auto, size);
}

.panel p {
margin: 0;
padding: 14px 16px;
line-height: 1.5;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS calc-size() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported in some modern browsers, but not all.

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