brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: interpolate-size: allow-keywords lets CSS animate to height: auto

Css
~/tips/tip-css-interpolate-size-height-auto

interpolate-size: allow-keywords;

Panels can slide open to their natural height without measuring them in JavaScript.

Transitioning from height: 0 to height: auto never worked, so everyone faked it with a large max-height. One property on the root changes that.

:root {
  interpolate-size: allow-keywords;
}
.panel {
  height: 0;
  overflow: hidden;
  transition: height 0.3s ease;
}
.panel.open {
  height: auto;
}

interpolate-size: allow-keywords allows the browser to animate between a length and an intrinsic size keyword such as auto, min-content or fit-content. The property is inherited, so setting it once on :root opts in the whole page. It is opt in for backwards compatibility, so existing sites keep behaving the way they did.

It also works for a details element if you transition the ::details-content part, which is how I would build an animated accordion now.

Support is the catch. Only Chromium browsers have it (Chrome 129 and later), Safari has it in a preview and Firefox not at all. Elsewhere the panel simply opens without animation, which is fine as a fallback. If the animation matters a lot, the calc-size() function is the per property alternative, with the same support limits.

Further reading: MDN: interpolate-size

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link