CSSMay 2026 ยท 5 min read

How to Create a CSS-Only Accordion (No JavaScript)

Build accessible, animated accordion components using HTML details/summary and CSS transitions.

๐Ÿ“ฆ
Try the CSS Animation Generator
Free, no signup
โ†’
DG
Derek Giordano
Designer & Developer
In this guide
01HTML details/summary Foundation02Styling the Accordion03Adding Smooth Animations04Accessibility Best Practices
โšก Key Takeaways
  • Build accessible, animated accordion components using HTML details/summary and CSS transitions.
  • HTML details/summary Foundation.
  • Styling the Accordion.
  • Adding Smooth Animations.
  • Accessibility Best Practices.

HTML details/summary Foundation

An accordion is a collapsible section list. HTML details and summary elements provide this natively: the browser handles open/close state, keyboard navigation, and screen reader semantics without JavaScript. Wrap each section in details, put the header in summary, and remaining content becomes the collapsible body. Add the open attribute for initially expanded sections. Semantically correct, progressively enhanced, and accessible by default.

Styling the Accordion

Style summary: remove default triangle with summary { list-style: none; } and summary::-webkit-details-marker { display: none; }. Add custom indicator (plus/minus or chevron) that rotates when open: details[open] summary .icon { transform: rotate(45deg); }. Style content with padding, borders, backgrounds. Standard CSS layout works naturally inside details elements.

Adding Smooth Animations

Smooth transitions are the trickiest part. The modern approach uses the CSS grid trick: set content wrapper to display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s; and switch to 1fr when open. Chrome 129+ supports interpolate-size: allow-keywords for height: auto transitions. Use the CSS Animation Generator to fine-tune easing curves.

Accessibility Best Practices

Native details/summary is already accessible โ€” keyboard-navigable (Enter/Space to toggle, Tab between sections), announces state to screen readers. To enhance: ensure color contrast on summary text, make click targets at least 44ร—44px for touch, keep indicators visible. For single-open behavior, the name attribute on details elements creates exclusive groups (Chrome 120+, Safari 17.2+).

Frequently Asked Questions

Is details/summary accessible by default?+
Yes. Browsers provide keyboard support, screen reader state announcement, and focus management. The most accessible accordion approach.
Can only one section be open at a time?+
With the name attribute (same name = exclusive group), yes. Supported in Chrome 120+, Safari 17.2+. For broader support, add a small JavaScript listener.
details/summary or JavaScript accordion?+
details/summary for most cases โ€” simpler, accessible by default, no JS. Use JavaScript only for complex behaviors like nested accordions or animation libraries.
Try it yourself

Use the CSS Animation Generator โ€” free, no signup required.

โšก Open CSS Animation Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.