Back to Snippets

Animated Exclusive Accordion with Details Name CSS

Four questions sit in a list and only one can be open at a time. Opening a second question closes the first, the panel height animates instead of snapping, and the whole thing is HTML and CSS.

The exclusive behavior comes from giving every details element the same name attribute, which the browser treats as a group in the same way it groups radio buttons. The ::details-content pseudo-element exposes the collapsible part so it can take a transition, and interpolate-size set to allow-keywords lets that transition run from a height of zero to a height of auto, which CSS could not animate before. The summary keeps its native button semantics, so keyboard and screen reader users get the accordion for free.

The name attribute and ::details-content work in every current browser. interpolate-size is still Chromium only in 2026, so Firefox and Safari open the panels without the slide.

0
#css
#html
#accordion
#details
#faq
#animation
#ui
#accessibility