A panel opens to its own height with nothing measuring it. Three mechanisms are
here: a one-row grid going from 0fr to 1fr, which works everywhere today;
the native interpolate-size route, which is the right answer where it exists; and
max-height, which is here so you can watch it get both the easing and the clipping
wrong.
/* works in every current browser */
.body{ display:grid; grid-template-rows:0fr;
transition:grid-template-rows .25s var(--m-ease-emph-decelerate) }
.fold.open .body{ grid-template-rows:1fr }
.body > .inner{ min-height:0; overflow:hidden } /* both required */
/* the native route, layered on top where it exists */
:root{ interpolate-size:allow-keywords }
@supports (interpolate-size: allow-keywords){
.body{ display:block; height:0; transition:height .25s }
.fold.open .body{ height:auto }
}
/* and the native element, for a disclosure that needs no JS at all */
details::details-content{
block-size:0; overflow:hidden;
transition: block-size .25s, content-visibility .25s allow-discrete;
}
details[open]::details-content{ block-size:auto }The JavaScript on this page toggles a class, sets
aria-expanded, and makes the closed panel inert. It never reads a height.
That last part is the one people forget: a closed max-height:0 panel still has
focusable children, so a keyboard user tabs into a panel they cannot see.