RSS Amplifier

CSS Tips by Theo Soti for Web and Frontend Developers · Aug 9, 2026

Build accessible accordions with details and summary

0
Sign in to vote or save

Theo Soti · Theo Soti

An accordion opening and closing smoothly using the native details and summary elements

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.


If you liked this tip, you might enjoy my guide “You Don’t Need JavaScript”, which contains more ways to build modern interfaces with HTML and CSS.

You can find it at https://theosoti.com/you-dont-need-js/.

Read the original on theosoti.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.