Skip to content
FEE
Frontend Engineering Essentials
Senior Level
Tone-Polished· 2026-07

[FEE-11102] calc-size() & interpolate-size — Animating to auto ​

INFO

Opt into keyword-size interpolation so height: 0 → height: auto works inside a CSS transition, without JavaScript, max-height hacks, or easing distortion.

Limited Availability

Currently supported in Chrome 129+/Edge 129+ only. Firefox and Safari support is in progress. Check the MDN compatibility table before using in production.

Context ​

CSS transitions require two numeric endpoints to interpolate between. Transitioning height: 0 to height: 200px works perfectly: both values are resolved pixel lengths at style-computation time, and the browser can compute every midpoint. The problem is auto.

auto is a layout keyword. Its resolution depends on the element's content, its containing block, and its flex or grid context. These factors are not known until the layout pass that comes after style computation. When the browser reaches the interpolation step, auto has no numeric value yet. The browser cannot compute the midpoint of 0px and ???px, so it skips the transition and snaps to the final state.

Accordions, disclosure widgets, drawer panels, and expandable cards all naturally want to animate between a collapsed height of 0 and an expanded height of "whatever the content needs." Without native support, teams were forced to choose between three imperfect workarounds.

The max-height hack: transition max-height from 0 to a large sentinel value like 9999px. Two significant problems: the easing curve is applied over the full 0px → 9999px range, not the actual 0px → content-height range, so the element shoots to its final position very early and then sits there for most of the transition duration. The timing is perceptually wrong and varies by content length.

The JavaScript scrollHeight approach: on expand, read element.scrollHeight (which returns the resolved pixel height after layout), assign it to element.style.height, wait for transitionend, then restore height: auto so the element can reflow freely afterward. This works correctly but requires event listeners, imperative DOM manipulation, and a forced layout read on every expand/collapse cycle.

The visibility: hidden workaround: keep elements in layout flow using visibility: hidden instead of height: 0. Avoids the missing-snapshot problem but forces elements to take up space when "hidden," which is rarely the desired behavior.

Chrome 129 shipped two new CSS features that solve this at the language level:

  • interpolate-size: allow-keywords: a CSS property that opts an element (or the entire document via :root) into keyword-size interpolation. With this set, height: auto can participate in CSS transitions and animations as if it were a numeric value.
  • calc-size(): a new CSS function that accepts an intrinsic sizing keyword (auto, min-content, max-content, fit-content) and an expression over size (the resolved value). It enables arithmetic on keyword sizes and also implicitly enables keyword interpolation for the specific property it is used on.

You are building a FAQ page with an accordion component. Each question expands to reveal its answer. The design calls for a smooth height transition: a real expansion from 0 to the natural content height, not a fade or a max-height approximation. The content of each answer varies in length, so a hardcoded pixel value is not an option.

Requirements:

  • Expand: height: 0 → height: auto with a smooth easing curve over 0.3 s.
  • Collapse: the reverse.
  • Pure CSS animation: no JavaScript height measurement.
  • Unsupported browsers (Firefox, Safari) receive a functional fallback using max-height.
  • No layout breakage if the content height changes (e.g., images load asynchronously).

With interpolate-size: allow-keywords on :root and a height transition on the panel, the accordion animation reduces to two CSS declarations.

Best Practices ​

  • SHOULD set interpolate-size: allow-keywords on :root as a progressive enhancement. Because the property is inherited, placing it on :root enables keyword-size transitions across the entire document. On browsers that do not support the property, the declaration is silently ignored. There is no visual difference or layout side effect. On Chrome 129+, it unlocks auto animations everywhere.

  • MUST provide a fallback for unsupported browsers. Use @supports (interpolate-size: allow-keywords) to gate the height transition, and provide a max-height transition inside a @supports not block. This ensures users on Firefox and Safari still get a functional (if imperfect) animation, and users on very old browsers see an instant show/hide with no broken layout.

  • SHOULD use calc-size(auto, size) when you need arithmetic on auto. For example, if a panel has 16px of vertical padding that should be included in the animated height, write height: calc-size(auto, size + 32px) rather than splitting it across multiple transitions. The size identifier inside calc-size() refers to the resolved value of the keyword (the natural content height). Any valid <calc-sum> expression is allowed.

  • SHOULD NOT use calc-size() and interpolate-size interchangeably for the same element: they solve adjacent problems. interpolate-size: allow-keywords is a policy applied to the element that affects all keyword-value transitions. calc-size() is a point-of-use value that implicitly enables interpolation for that specific declaration only. Prefer interpolate-size: allow-keywords on :root for global enablement, and reach for calc-size() only when arithmetic on the resolved size is needed.

  • SHOULD NOT rely on interpolate-size for layout-critical interactions without testing on Firefox and Safari. Neither browser supports it yet. Use it as an enhancement layer over a working baseline implementation.

  • MAY use interpolate-size: allow-keywords with @keyframes animations in addition to transition. The property affects both. A keyframe that goes from { height: 0 } to { height: auto } will animate correctly when interpolate-size: allow-keywords is in scope.

  • MAY use calc-size() with keywords other than auto: min-content, max-content, and fit-content are all valid. For example, calc-size(max-content, size * 0.75) yields 75% of the element's maximum intrinsic width.

Design Thinking ​

Why auto could not animate ​

CSS transitions operate by capturing two computed style snapshots: one before the triggering change and one after. The browser interpolates between those two snapshots over the specified duration.

The key word is "computed." Style computation resolves keywords, performs cascade and inheritance, and calculates property values, but it does not perform layout. auto is resolved during layout, which happens after style computation. When the browser's transition machinery asks "what is the numeric value of height: auto?" during style computation, layout has not run yet. The answer is: unknown. With no numeric value, no interpolation is possible, and the transition is skipped.

This is a consequence of the CSS processing model, not a browser bug or oversight. Style computation and layout are separate phases, and the transition system lives in the style computation phase.

How max-height worked, and why it was wrong ​

The max-height hack sidesteps the problem by replacing the unanswerable question ("what is auto?") with an answerable one ("what is 9999px?"). Transitioning max-height: 0 to max-height: 9999px gives the browser two known numbers.

The problem is that the easing function (whether ease, ease-in-out, or a custom cubic bezier) is applied over the full numeric range of the transition, which is 0 to 9999 (or whatever sentinel is used). If the actual content height is 200px, then 97.9% of the transition's numeric range is unused. The element reaches its natural height after only 2% of the animation timeline. The browser then interpolates max-height from 200px to 9999px for the remaining 98% of the duration, but the element's rendered height is already at 200px and cannot grow further because the content is only 200px tall. The result is an abrupt snap to position followed by a long invisible animation, making the easing feel completely wrong.

Smaller sentinel values (like 500px) reduce the distortion but require knowing a rough upper bound for the content height, which defeats the purpose of using auto in the first place.

How the JS scrollHeight approach worked ​

element.scrollHeight returns the element's full rendered height including overflow (effectively the pixel equivalent of height: auto). Reading it after layout gives the resolved numeric value that auto would produce.

The sequence on expand:

  1. Set height from 0 to the scrollHeight value. This is a 0px → Npx transition with a known numeric endpoint. It animates correctly with the right easing.
  2. Listen for transitionend. When it fires, restore height: auto so the element can reflow freely if its content changes (e.g., a lazy-loaded image).

The sequence on collapse is the reverse: read scrollHeight, set it as the starting height, trigger a reflow to register the value, then set height: 0 to begin the transition.

This works correctly, but it forces a layout read (scrollHeight) every time the user interacts with the component. Layout reads are synchronous and can trigger reflow, which is expensive on complex pages. The event listener adds imperative wiring that CSS should not require.

Why interpolate-size is better ​

interpolate-size: allow-keywords instructs the browser's style engine to resolve intrinsic keywords like auto before the interpolation step runs. The browser performs a speculative layout to find the resolved value, then uses that pixel value as the interpolation endpoint.

The result is a transition that is semantically identical to the JS approach but implemented at the platform level: the easing is applied over the correct range (0px to the actual content height), the timing is accurate, and no JavaScript is required. The resolved value is also dynamic: if the content changes between transitions, the next transition uses the updated resolved value automatically.

calc-size() extends this by allowing the resolved value to be used in arithmetic expressions. calc-size(auto, size + 2rem) resolves auto first, then adds 2rem to the result. This cannot be expressed with interpolate-size alone, which only enables keyword-as-endpoint; it cannot modify the resolved value.

Example ​

An accordion component. Each panel expands from height: 0 to height: auto using interpolate-size: allow-keywords. A max-height fallback is provided for unsupported browsers.

html
<div class="accordion">
  <button class="accordion__trigger" aria-expanded="false"
          onclick="this.setAttribute('aria-expanded',
            this.getAttribute('aria-expanded') === 'true' ? 'false' : 'true')">
    What is CSS?
  </button>
  <div class="accordion__panel">
    <p>CSS (Cascading Style Sheets) is a stylesheet language used to describe the
    presentation of a document written in HTML or XML.</p>
  </div>
</div>
css
/* Base: panel is collapsed */
.accordion__panel {
  height: 0;
  overflow: hidden;
}

/* Progressive enhancement: browsers with interpolate-size get smooth height animation */
@supports (interpolate-size: allow-keywords) {
  :root { interpolate-size: allow-keywords; }
  .accordion__panel { transition: height 0.3s ease; }
  .accordion__trigger[aria-expanded="true"] + .accordion__panel {
    height: auto;
  }
}

/* Fallback: browsers without interpolate-size get a max-height animation instead */
@supports not (interpolate-size: allow-keywords) {
  .accordion__panel { max-height: 0; transition: max-height 0.3s ease; }
  .accordion__trigger[aria-expanded="true"] + .accordion__panel {
    max-height: 500px; /* set high enough to cover content */
  }
}

How the expansion works ​

When the trigger is clicked and aria-expanded becomes "true":

  1. The selector .accordion__trigger[aria-expanded="true"] + .accordion__panel matches, changing the panel's height from 0 to auto.
  2. Because interpolate-size: allow-keywords is set on :root, the browser resolves auto speculatively before computing the transition midpoints.
  3. The height transition fires from 0px to the resolved pixel value of auto, with the easing applied over that exact range.
  4. The panel expands smoothly to its natural content height.

On collapse, the attribute returns to "false", the selector stops matching, height reverts to 0, and the transition plays in reverse.

Using calc-size() for padded heights ​

If the panel has vertical padding (padding-block: 1rem) that should be included in the animated height, use calc-size() to add the padding to the resolved auto value:

css
.accordion__trigger[aria-expanded="true"] + .accordion__panel {
  /* Animate to content height + 2rem (top + bottom padding) */
  height: calc-size(auto, size + 2rem);
}

The size identifier resolves to the same pixel value that bare auto would resolve to. The addition then produces a target height that accounts for the padding. This is equivalent to the JS pattern of reading scrollHeight and adding paddingTop + paddingBottom, but entirely declarative.

Using calc-size() with max-content ​

calc-size() works with any intrinsic sizing keyword. To constrain an element to 75% of its natural maximum width while still animating correctly:

css
.panel {
  width: calc-size(max-content, size * 0.75);
  transition: width 0.3s ease;
}

The size identifier inside calc-size(max-content, ...) resolves to the element's max-content width. Multiplying by 0.75 produces a width that is 75% of the maximum natural width. Transitions to and from this value work correctly because calc-size() implicitly enables keyword interpolation for the property.

Reduced motion ​

Wrap animation-only rules in @media (prefers-reduced-motion: no-preference) so users who have requested reduced motion see instant show/hide rather than a transition:

css
/* Base: panel is collapsed */
.accordion__panel {
  height: 0;
  overflow: hidden;
}

/* Progressive enhancement: browsers with interpolate-size get smooth height animation */
@supports (interpolate-size: allow-keywords) {
  :root { interpolate-size: allow-keywords; }

  @media (prefers-reduced-motion: no-preference) {
    .accordion__panel { transition: height 0.3s ease; }
  }

  .accordion__trigger[aria-expanded="true"] + .accordion__panel {
    height: auto;
  }
}

/* Fallback: browsers without interpolate-size get a max-height animation instead */
@supports not (interpolate-size: allow-keywords) {
  @media (prefers-reduced-motion: no-preference) {
    .accordion__panel { max-height: 0; transition: max-height 0.3s ease; }
    .accordion__trigger[aria-expanded="true"] + .accordion__panel {
      max-height: 500px;
    }
  }
}

This layering ensures:

  • Chrome 129+, motion allowed: smooth height: auto transition.
  • Chrome 129+, reduced motion: instant expand/collapse.
  • Firefox/Safari, motion allowed: max-height approximation.
  • Firefox/Safari, reduced motion: instant expand/collapse.

Deep Dive ​

interpolate-size inheritance and scope ​

interpolate-size is an inherited property. Setting it on :root enables keyword-size transitions for every element in the document. This is intentional: the recommended pattern is to set it on :root and let it inherit everywhere.

You can also scope it more narrowly by setting it on a specific container:

css
.expandable-section {
  interpolate-size: allow-keywords;
}

Only elements inside .expandable-section would have keyword interpolation enabled. The rest of the document is unaffected. This can be useful when you want to audit or limit the scope of the behavior during a gradual rollout.

The default value is interpolate-size: numeric-only, which preserves the pre-Chrome-129 behavior. Opting in at :root does not change any existing transitions that operate between two numeric values. Those are unaffected. Only transitions that involve an intrinsic keyword on one or both ends are changed.

calc-size() and implicit interpolation opt-in ​

When a property's value includes calc-size(), the browser implicitly enables keyword interpolation for that declaration, even if interpolate-size is not set on the element. This means calc-size() is self-contained: you do not need to set interpolate-size: allow-keywords on :root to use it.

css
/* Works without interpolate-size: allow-keywords on :root */
.panel {
  height: calc-size(auto, size);
  transition: height 0.3s ease;
}
.panel.collapsed {
  height: 0;
}

calc-size(auto, size) with no modification is equivalent to auto but with interpolation enabled. This can be used as a targeted opt-in when you do not want to enable keyword interpolation globally.

Speculative layout and performance ​

When the browser needs to resolve auto for an interpolation endpoint, it performs a speculative layout pass to determine what the element's height would be. This is more work than resolving a static pixel value but less work than a full document reflow.

In practice, the cost is comparable to reading scrollHeight in JavaScript: both require a layout pass. The advantage of the CSS approach is that it is integrated into the browser's rendering pipeline rather than triggered by JavaScript, which allows the browser to schedule and batch it more efficiently.

For very large or complex documents with many simultaneous keyword-size transitions, you may observe layout pressure. Profile before assuming this is a bottleneck.

@keyframes and interpolate-size ​

interpolate-size: allow-keywords applies to @keyframes animations as well as transition. A keyframe animation with keyword values animates correctly when the property is in scope:

css
@keyframes expand {
  from { height: 0; }
  to   { height: auto; }
}

.panel {
  animation: expand 0.3s ease forwards;
}

With interpolate-size: allow-keywords set on :root (or on the .panel element), this animation plays correctly. Without it, the browser snaps to height: auto at the first frame.

Interaction with overflow ​

When animating height: 0 to height: auto, the content must be hidden at height: 0. Set overflow: hidden on the element to clip content during the transition. After the transition completes, height: auto allows the element to grow freely, but overflow: hidden remains and will clip any content that overflows. If the expanded state should allow overflow (e.g., a dropdown with a visible tooltip inside), change overflow to visible after the transition ends, or use overflow: clip with clip-path for a more CSS-native solution.

css
.accordion__panel {
  height: 0;
  overflow: hidden;
  transition: height 0.3s ease;
}

/* Reveal overflow after animation completes using a delayed transition */
.accordion__trigger[aria-expanded="true"] + .accordion__panel {
  height: auto;
  overflow: visible;
  /* Delay overflow change until height transition is done */
  transition: height 0.3s ease, overflow 0s 0.3s;
}

Browser Support ​

Browserinterpolate-sizecalc-size()Notes
Chrome129129
Edge129129Chromium-based
FirefoxNot supportedNot supportedIn progress
SafariNot supportedNot supportedIn progress

Progressive enhancement check:

css
@supports (interpolate-size: allow-keywords) {
  :root { interpolate-size: allow-keywords; }
  /* keyword-size transitions enabled */
}

@supports not (interpolate-size: allow-keywords) {
  /* max-height fallback */
}

Or via JavaScript:

js
const supported = CSS.supports('interpolate-size', 'allow-keywords');

Because calc-size() is a value-level feature, it cannot be checked with CSS.supports() directly. Use the interpolate-size property check as a proxy: both features shipped together in Chrome 129 and will ship together in other browsers.

Firefox has an open implementation ticket and has expressed intent to ship. Safari's WebKit team has flagged interpolate-size as a feature they are tracking. Check the MDN compatibility table at the link below for the latest status as browser support evolves.

  • FEE-11101 @starting-style — Entry Animations Without JavaScript: Both features solve the problem of animating display-state changes with pure CSS. @starting-style provides the "before" snapshot for entry transitions; interpolate-size provides the resolved numeric endpoint for keyword-valued transitions. They are complementary and can be combined: an element can have both a @starting-style entry animation and a height: auto expansion.

References ​