Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The interpolate-size property

Reference for the CSS interpolate-size property: opt in to animating and transitioning between a length and keywords like auto. Values, example and limited support.

CSS cannot normally transition height from 0 to auto, because auto is a keyword with no number to calculate with. The interpolate-size property is an opt-in switch: with allow-keywords, the browser can interpolate between lengths and intrinsic-size keywords such as auto, min-content, max-content and fit-content.

CSS
:root {
  interpolate-size: allow-keywords;
}

Try it

Opening a panel to its natural height

In a supporting browser the panel slides open smoothly. Without support it jumps open at once, because a transition between 0 and auto does not run.

Syntax

CSS
interpolate-size: numeric-only | allow-keywords
  • Initial value: numeric-only
  • Applies to: all elements
  • Inherited: yes
  • Animatable: no
  • Computed value: as specified

Values

Value Description
numeric-only Only numeric values can be interpolated. A change to or from auto is instant.
allow-keywords Intrinsic-size keywords (auto, min-content, max-content, fit-content) can be interpolated with lengths and percentages in size properties such as width, height and max-height.

Usage notes

  • It is inherited, so setting it once on :root enables the behavior for the whole page, and individual elements can opt out with numeric-only.
  • Only sizing properties. It covers properties like width, height, min-*, max-* and flex-basis. It does not make other keywords animatable.
  • Pair with overflow: hidden (or clip) on the animating box so content does not spill out while the box is smaller.
  • calc-size() is a related function that gives finer control, for example calc-size(auto, size + 20px).
  • Respect motion preferences. Wrap long transitions in a prefers-reduced-motion: no-preference query.
  • Old alternatives. Before this property, developers animated max-height to a guessed value, or used a grid-template-rows: 0fr to 1fr trick.

Browser support

Limited: supported in Chromium-based browsers, but not yet in all major browsers. Treat it as progressive enhancement; the panel simply opens without animation elsewhere.