6.3 · Motion

Animate to auto: interpolate-size

Transition to height: auto with one line on the root.

height: auto could never be transitioned. interpolate-size: allow-keywords on the root fixes that for keywords like auto, min-content and fit-content.

Combined with ::details-content, the part of a <details> element that opens and closes, accordions animate with no JavaScript. calc-size(auto, size + 1rem) does the same for calculations based on a keyword.

Before
el.style.height = el.scrollHeight + 'px'
el.addEventListener('transitionend', () => {
  el.style.height = 'auto'
}, { once: true })
Now
:root { interpolate-size: allow-keywords; }

details::details-content {
  block-size: 0;
  transition: block-size 0.4s,
    content-visibility 0.4s allow-discrete;
}
details[open]::details-content {
  block-size: auto;
}