|$ curl https://forge-ai.dev/api/markdown?path=docs/components/accordions
$cat docs/accordions.md
updated Recently·20 min read·published

Accordions

CSSHTMLTailwindBootstrapUIIntermediate🎯Free Tools
Introduction

Accordions compress long content into collapsible panels. This guide covers native HTML details/summary, single-open and multi-open JavaScript accordions, FAQ patterns, and framework implementations in Tailwind CSS and Bootstrap.

info

Prefer <details> and <summary> for no-JS disclosure widgets. For custom animations or single-panel behavior, use a real <button> with aria-expanded and a controlled panel.
Details/Summary

Native HTML accordion using the <details> and <summary> elements — no JavaScript needed, fully accessible.

details
Live
untitled.html
HTML
1<div class="wrapper">
2 <details class="accordion" open>
3 <summary class="accordion-header">
4 What is this component?
5 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
6 <polyline points="6 9 12 15 18 9"/>
7 </svg>
8 </summary>
9 <div class="accordion-body">
10 This is a native HTML accordion built with the details and summary elements. It supports an open state by default using the open attribute, and browsers handle all the show/hide logic natively.
11 </div>
12 </details>
13 <details class="accordion">
14 <summary class="accordion-header">
15 How does it work?
16 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
17 <polyline points="6 9 12 15 18 9"/>
18 </svg>
19 </summary>
20 <div class="accordion-body">
21 The details element creates a disclosure widget. When open, its contents are visible. The summary element provides the visible label. Clicking the summary toggles the open state automatically.
22 </div>
23 </details>
24 <details class="accordion">
25 <summary class="accordion-header">
26 What are the benefits?
27 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
28 <polyline points="6 9 12 15 18 9"/>
29 </svg>
30 </summary>
31 <div class="accordion-body">
32 Zero JavaScript required, built-in keyboard navigation (Enter/Space to toggle), screen reader friendly, and semantic HTML that works with any CSS framework.
33 </div>
34 </details>
35</div>
preview
JavaScript Accordion

Custom accordion with animated open/close and single-item-only mode — only one panel open at a time.

js-accordion
Live
untitled.html
HTML
1<div class="wrapper" data-single-group>
2 <div class="js-accordion">
3 <button class="js-header">
4 <span>
5 Account Settings
6 </span>
7 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
8 <polyline points="6 9 12 15 18 9"/>
9 </svg>
10 </button>
11 <div class="js-body">
12 <div class="js-inner">
13 Manage your profile, password, and connected accounts.
14 </div>
15 </div>
16 </div>
17 <div class="js-accordion">
18 <button class="js-header">
19 <span>
20 Notifications
21 </span>
22 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
23 <polyline points="6 9 12 15 18 9"/>
24 </svg>
25 </button>
26 <div class="js-body">
27 <div class="js-inner">
28 Choose which emails, push alerts, and in-app messages you receive.
29 </div>
30 </div>
31 </div>
32 <div class="js-accordion">
33 <button class="js-header">
34 <span>
35 Privacy
36 </span>
37 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
38 <polyline points="6 9 12 15 18 9"/>
39 </svg>
40 </button>
41 <div class="js-body">
42 <div class="js-inner">
43 Review how your data is used, exported, and shared with third parties.
44 </div>
45 </div>
46 </div>
47</div>
preview
FAQ Style

FAQ-style accordion with compact design, larger click targets, and smooth transitions.

faq
Live
untitled.html
HTML
1<div class="wrapper">
2 <div class="faq-item">
3 <button class="faq-q">
4 How do I reset my password?
5 <svg class="faq-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
6 <polyline points="6 9 12 15 18 9"/>
7 </svg>
8 </button>
9 <div class="faq-a">
10 <p>
11 Go to Settings &gt; Security &gt; Reset Password. Enter your email address and we'll send you a reset link. The link expires in 24 hours.
12 </p>
13 </div>
14 </div>
15 <div class="faq-item">
16 <button class="faq-q">
17 Can I export my data?
18 <svg class="faq-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
19 <polyline points="6 9 12 15 18 9"/>
20 </svg>
21 </button>
22 <div class="faq-a">
23 <p>
24 Yes. Navigate to Settings &gt; Data &gt; Export. You can download your data as JSON, CSV, or PDF. Large exports are emailed as a zip file.
25 </p>
26 </div>
27 </div>
28 <div class="faq-item">
29 <button class="faq-q">
30 Is there a mobile app?
31 <svg class="faq-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14">
32 <polyline points="6 9 12 15 18 9"/>
33 </svg>
34 </button>
35 <div class="faq-a">
36 <p>
37 Our mobile app is available on iOS and Android. Download it from the App Store or Google Play Store for on-the-go access.
38 </p>
39 </div>
40 </div>
41</div>
preview
Multi-Open Accordion

Independent panels that stay open until the user closes them. Useful for comparison or reference content.

multi-open
Live
untitled.html
HTML
1<div class="wrapper" data-multi-group>
2 <div class="card">
3 <button class="card-header">
4 <span>
5 Plan
6 </span>
7 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
8 <polyline points="6 9 12 15 18 9"/>
9 </svg>
10 </button>
11 <div class="card-body">
12 <div class="card-body-inner">
13 Define scope, user stories, and architecture before writing code.
14 </div>
15 </div>
16 </div>
17 <div class="card">
18 <button class="card-header">
19 <span>
20 Build
21 </span>
22 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
23 <polyline points="6 9 12 15 18 9"/>
24 </svg>
25 </button>
26 <div class="card-body">
27 <div class="card-body-inner">
28 Develop features in small iterations with continuous integration and review.
29 </div>
30 </div>
31 </div>
32 <div class="card">
33 <button class="card-header">
34 <span>
35 Launch
36 </span>
37 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
38 <polyline points="6 9 12 15 18 9"/>
39 </svg>
40 </button>
41 <div class="card-body">
42 <div class="card-body-inner">
43 Deploy to production, monitor health, and iterate based on real usage.
44 </div>
45 </div>
46 </div>
47</div>
preview
Accessibility

Accordions hide content until requested, so screen-reader users and keyboard users need clear state and focus management.

  • Use <details>/<summary> for native keyboard support and automatic aria-expanded mapping.
  • Custom accordions need a real <button> trigger with aria-expanded and aria-controls pointing to the panel id.
  • Keep focus visible; add a focus ring or outline on the trigger.
  • Single-open groups should move focus logically and announce the expanded panel.
  • Avoid nesting interactive controls inside the summary or trigger unless the pattern is truly needed.

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.