Skip to content

Search

Animating the <details> element without JavaScript

CSSA11yPerformance

With interpolate-size and ::details-content, the <details> element opens and closes smoothly. Browsers without support open it instantly, as they always have.

by
6 min read

Why could we never transition to height: auto? Because CSS can’t calculate between a length and a keyword. For an accordion that meant a choice: let it jump open, or measure the content with JavaScript.

TL;DR

Opt in with interpolate-size: allow-keywords, animate height on ::details-content and transition content-visibility with allow-discrete, so closing animates too. Wrap all of it in @supports and prefers-reduced-motion. Every other browser opens <details> instantly, as it always has.

Why height: auto never animated

A transition needs two values it can interpolate between. 0 and 300px work. 0 and auto don’t, because auto is only resolved during layout. So the browser doesn’t animate at all, it switches.

We built three kinds of workarounds for this:

  • max-height with a generous value. The transition runs to the maximum, not to the real height. Closing starts with a noticeable delay, because the first part of the transition happens above the content.
  • Measuring with JavaScript. Read scrollHeight, set it as a pixel value, animate, reset. It works, but needs a script and breaks as soon as content changes after measuring.
  • grid-template-rows from 0fr to 1fr. Pure CSS and fairly robust, but it needs an extra wrapper element around the content.

All three work around the symptom. None of them lets the browser do what it already knows: how tall the content is.

Opting in with interpolate-size

Since Chrome 129, interpolate-size: allow-keywords lets the browser animate to and from auto, min-content, max-content and fit-content. It is an opt-in for a reason: many existing sites rely on these keywords not animating, so switching it on for everyone would break them.

The property is inherited. Most examples set it once on :root. I prefer setting it on the component that needs it:

accordion.css
.accordion {
  interpolate-size: allow-keywords;
}

Why the narrower scope? On :root, every existing transition that touches height or width and hits auto will suddenly animate. That might be what you want. On a site that has grown over years, it is a change you want to make deliberately, one component at a time.

There is also calc-size(), for when we need to calculate with an intrinsic size, for example calc-size(auto, size + 2rem). For plain animations interpolate-size is enough. One limit applies to both: we can’t animate between two keywords. One end has to be a length or a percentage.

Animating both ways with ::details-content

<details> hides its content itself, and for a long time there was nothing we could style about the hidden part. ::details-content changes that. It selects everything inside <details> except the <summary>, and it works in Chrome 131, Firefox 143 and Safari 18.4.

Opening is the easy part: height goes from 0 to auto. Closing is trickier. When <details> closes, the browser hides the content right away with content-visibility: hidden, and the animation would never be seen. Transitioning content-visibility with allow-discrete keeps the content visible until height has reached 0.

The accordion on this site uses the same CSS, only with its own class names:

accordion.css
@supports (interpolate-size: allow-keywords) {
  @media (prefers-reduced-motion: no-preference) {
    .accordion {
      interpolate-size: allow-keywords;
    }

    .accordion__item::details-content {
      height: 0;
      overflow: clip;
      transition:
        height 200ms ease,
        content-visibility 200ms ease allow-discrete;
    }

    .accordion__item[open]::details-content {
      height: auto;
    }
  }
}

Warning: Keep height: 0 inside @supports

Firefox and Safari already support ::details-content, but not interpolate-size. If height: 0 sits outside the @supports block, the content stays at zero height in those browsers and can’t be read at all.

The example in Bramus’s article on styling <details> solves this with a fallback: a fixed height of 150px and a scrollbar. I prefer to let unsupported browsers do what <details> has always done and open instantly. The animation is an enhancement, not a feature the content depends on.

Try it here. With reduced motion turned on in your system settings, the sections open without animation:

Does anything change for keyboard users?

No. <summary> keeps its role and its expanded state, Enter and Space still toggle it. The animation only changes how the content appears.

What happens with find in page?

In Chromium browsers, find in page, text fragments and links to an element inside still open the matching section, and the animation runs as it opens.

Why 200 milliseconds?

Long enough to follow where the content comes from, short enough not to slow anyone down. The arrow icon in this component turns in 150 ms, so both movements feel related.

Support, fallback and cost

Browser support as of 22 October 2026
Feature Chrome and Edge Firefox Safari
interpolate-size 129 not yet, positive Technology Preview 254
calc-size() 129 not yet Technology Preview 254
::details-content 131 143 18.4

Safari Technology Preview 254 shipped both features on 8 October 2026. Mozilla has a positive standards position and an open bug. Until both reach stable releases, most visitors on Safari and Firefox get the instant version, which is a perfectly good version.

The animation has a price. height triggers layout on every frame, and the web.dev guide on animations is clear about that:

Avoid any property that triggers layout or paint unless it’s absolutely necessary.

— web.dev: How to create high-performance CSS animations

For a handful of short sections, I think that is acceptable. For a long FAQ with heavy content, measure it in the Performance panel with CPU throttling before you ship it. If the frames drop, a pure opacity fade on ::details-content is the cheaper alternative.

Conclusion

A smoothly opening <details> used to need JavaScript or a workaround. Now a few lines of CSS are enough, and browsers without support lose nothing. Is there a component in your project that measures heights in JavaScript and could be a <details> instead?

Further reading

Written by

Oliver Scheffler

I’ve been building websites for 25 years and write here about frontend, accessibility and performance – mostly about things I struggled with myself.

Accessible tabs, with CSS that reads the state

A11yJavaScriptCSS

The ARIA tabs pattern looks small, but it hides a dozen decisions. Here is the markup, the keyboard code and a way of writing CSS that can't drift from what screen readers are told, with a position on every contested point.

10 min read