How to Build a Controlled Accordion on the Details Element

A CoreUI accordion with Shipping, Returns and Payment items on a purple gradient, the Returns item halfway open under the mouse pointer

The <details> element is a good base for an accordion. The browser gives it keyboard support, exposes its expanded state to assistive technology, closes the other open item of a group that shares a name, and, in browsers that search closed disclosures, opens an item when a find-in-page match is inside it. None of that needs JavaScript, and if nothing in your page has to approve or follow which items are open, a plain <details name> group is all you need.

The trouble starts when the open items belong to your state: a form wizard that refuses to open step two before step one is valid, a route that decides which section is open, a React or Vue component with a value and an onChange. A <details> element toggles itself, and it does not wait for your permission. This guide shows how to build an accordion on top of it that does what the state says, and only that.

Read More…

How to build an accordion in Vue

Accordions organize large amounts of content into collapsible sections, improving page scannability and reducing initial visual complexity. As the creator of CoreUI, I’ve implemented accordion components in countless enterprise applications. A Vue accordion requires reactive state to track which items are open, methods to toggle items, and transitions for smooth expand/collapse animations. This approach creates a reusable accordion without external dependencies.

Read More…
Subscribe to our newsletter
Get early information about new products, product updates and blog posts.