/* Pass a value through calc-size() */
calc-size(auto, size)
calc-size(fit-content, size)
/* Perform a calculation */
calc-size(min-content, size + 100px)
calc-size(fit-content, size / 2)
/* Calculation including a function */
calc-size(auto, round(up, size, 50px))`calc-size()` CSS function / notebook
`calc-size()` CSS function
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
section {
height: calc-size(calc-size(max-content, size), size + 2rem);
} :root {
--intrinsic-size: calc-size(max-content, size);
}
section {
height: calc-size(var(--intrinsic-size), size + 2rem);
} section {
height: calc-size(300px + 2rem, size / 2);
} section {
height: calc-size(any, 300px * 1.5); /* Returns 450px */
}section {
width: 0;
transition: width ease 1s;
}
section:hover,
section:focus {
width: calc-size(auto, size);
}section {
width: 0;
transition: width ease 1s;
}
section:hover,
section:focus {
width: calc-size(auto, size + 2rem);
}@keyframes narrower {
from {
width: fit-content;
}
to {
width: calc-size(fit-content, size * 0.7);
}
}<section>
<h2>Favorite quote</h2>
<p>
Fashion is something so ugly it has to be changed every fifteen minutes.
</p>
</section>