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

Accordions

CSSHTMLUIIntermediate

Collapsible sections with pure CSS details/summary elements and interactive JavaScript accordions with animated open/close.

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 <span class="icon">
6
7 </span>
8 </summary>
9 <div class="accordion-body">
10 This is a native HTML accordion built with the details and summary elements. It supports 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 <span class="icon">
17 +
18 </span>
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 <span class="icon">
28 +
29 </span>
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, single-item-only mode (one open at a time), and smooth height transitions.

js-accordion
Live
untitled.html
HTML
1<div class="wrapper" id="accordion-group">
2 <div class="js-accordion open">
3 <button class="js-header" data-index="0">
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" style="max-height:200px">
12 <div class="js-inner">
13 <label class="field">
14 <span>
15 Full Name
16 </span>
17 <input type="text" value="Jane Doe" readonly/>
18 </label>
19 <label class="field">
20 <span>
21 Email
22 </span>
23 <input type="email" value="jane@example.com" readonly/>
24 </label>
25 </div>
26 </div>
27 </div>
28 <div class="js-accordion">
29 <button class="js-header" data-index="1">
30 <span>
31 Notifications
32 </span>
33 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
34 <polyline points="6 9 12 15 18 9"/>
35 </svg>
36 </button>
37 <div class="js-body">
38 <div class="js-inner">
39 <label class="toggle-field">
40 <span>
41 Email notifications
42 </span>
43 <input type="checkbox" checked/>
44 </label>
45 <label class="toggle-field">
46 <span>
47 Push notifications
48 </span>
49 <input type="checkbox"/>
50 </label>
51 <label class="toggle-field">
52 <span>
53 SMS alerts
54 </span>
55 <input type="checkbox"/>
56 </label>
57 </div>
58 </div>
59 </div>
60 <div class="js-accordion">
61 <button class="js-header" data-index="2">
62 <span>
63 Privacy
64 </span>
65 <svg class="arrow" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
66 <polyline points="6 9 12 15 18 9"/>
67 </svg>
68 </button>
69 <div class="js-body">
70 <div class="js-inner">
71 <p class="privacy-text">
72 Your privacy settings control how your data is used and shared. Review and adjust your preferences below.
73 </p>
74 <button class="action-btn">
75 Manage Privacy
76 </button>
77 </div>
78 </div>
79 </div>
80</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 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 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 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