Make smooth accordions without JavaScript.
The useful part starts with the <details> and <summary> elements.
They give you native disclosure semantics and keyboard interaction without recreating the component in JavaScript.
But what about smooth animations?
This is where CSS Grid can help. Instead of relying on a guessed max-height, place the accordion content inside a grid row and transition it between 0fr and 1fr.
The closed state uses a row height of 0fr. When the <details> element opens, the row changes to 1fr. A child wrapper with overflow: hidden keeps the content clipped during the transition.
Keep <summary> as the trigger. The animation should improve the native component, not replace its keyboard behavior or accessible name.
Also respect reduced-motion preferences when adding the transition.
Want to build modern interfaces with less JavaScript?
I wrote a guide about building modern UI with HTML and CSS first. It covers practical patterns you can use before reaching for JavaScript.
Learn more