Skip to content
Knsept
Free playbook

Smooth accordion

A FAQ accordion built on native details/summary, with a smooth open and close animation and an optional one-open-at-a-time mode.

CSSJavaScriptUI Widgets Updated Oct 23, 2026
Live demo Reduced motion is on, so effects are toned down
<div class="accordion" data-single-open>
  <details>
    <summary>Do I need a framework?</summary>
    <div class="accordion-body"><p>No. Every widget here is plain HTML, CSS and JavaScript you can paste into any project.</p></div>
  </details>
  <details>
    <summary>Does it work without JavaScript?</summary>
    <div class="accordion-body"><p>Yes. It's built on the native details element, so it opens and closes even if the script never loads.</p></div>
  </details>
  <details>
    <summary>Is it accessible?</summary>
    <div class="accordion-body"><p>The browser gives details/summary keyboard support and the right semantics for free.</p></div>
  </details>
</div>

The base is the native <details> element, which already handles keyboard access, screen-reader semantics, and even "find in page" for closed content in modern browsers. If the script never loads, everything still opens and closes.

The script only adds the smoothness: it stops the instant toggle (preventDefault), then uses the Web Animations API to animate the body's height between 0 and its real scrollHeight. When closing, open is removed after the animation ends, so the content doesn't vanish mid-slide.

Add data-single-open to the wrapper to close other items when one opens. With reduced motion on, items open and close in a quick 120ms.

More from the library

Navigation live

Sliding tabs

Accessible tabs with an indicator that glides between them. Full keyboard support, works at any width.

Navigation live

Animated menu button

A hamburger icon that morphs into an X and opens a menu. Correct aria-expanded, Escape to close, focus handled.

Scroll & motion live

Count-up stats

Numbers that count up when they scroll into view, with easing and formatting. A quicker count with reduced motion.