Accordions
Native disclosures with familiar keyboard interaction. No state library required.
Frequently asked questions
Independent details elements allow several answers to remain open.
Do I need JavaScript?
No. The framework is CSS only. This accordion uses the browser’s native details and summary elements.
Can I customize the design?
Yes. Override design tokens, combine utility classes, or add your own stylesheet after StyloftCSS.
Can I use it in commercial projects?
Yes. StyloftCSS is MIT licensed. Include its copyright and license notice in copies of the software.
View HTML / PlaygroundHTML source
<div class="sl-stack sl-gap-4">
<details class="sl-details" open>
<summary>Do I need JavaScript?</summary>
<p>
No. The framework is CSS only. This accordion uses the browser’s native details
and summary elements.
</p>
</details>
<details class="sl-details">
<summary>Can I customize the design?</summary>
<p>
Yes. Override design tokens, combine utility classes, or add your own stylesheet
after StyloftCSS.
</p>
</details>
<details class="sl-details">
<summary>Can I use it in commercial projects?</summary>
<p>
Yes. StyloftCSS is MIT licensed. Include its copyright and license notice in
copies of the software.
</p>
</details>
</div>A single disclosure
A little more detail
Some information is useful when you need it, and quieter when you don't.
Read the complete guide ↗View HTML / PlaygroundHTML source
<details class="sl-details demo-narrow">
<summary>A little more detail</summary>
<div class="sl-stack">
<p>Some information is useful when you need it, and quieter when you don't.</p>
<a href="/getting-started/">Read the complete guide ↗</a>
</div>
</details>Only one open at a time
A shared name creates a native exclusive group. Opening a second item closes the first; closing everything is allowed.
The foundation
One shared name, one open disclosure. Native keyboard behavior, no runtime JavaScript.
The palette
One shared name, one open disclosure. Native keyboard behavior, no runtime JavaScript.
The details
One shared name, one open disclosure. Native keyboard behavior, no runtime JavaScript.
View HTML / PlaygroundHTML source
<div class="sl-stack" id="exclusive-accordion">
<details class="sl-details" name="exclusive-demo" open>
<summary>The foundation</summary>
<p>
One shared name, one open disclosure. Native keyboard behavior, no runtime
JavaScript.
</p>
</details>
<details class="sl-details" name="exclusive-demo">
<summary>The palette</summary>
<p>
One shared name, one open disclosure. Native keyboard behavior, no runtime
JavaScript.
</p>
</details>
<details class="sl-details" name="exclusive-demo">
<summary>The details</summary>
<p>
One shared name, one open disclosure. Native keyboard behavior, no runtime
JavaScript.
</p>
</details>
</div>Several open at the same time
Omit name to let readers compare multiple answers.
First answer
This answer can remain open while another is expanded.
Second answer
This answer can remain open while another is expanded.
Third answer
This answer can remain open while another is expanded.
View HTML / PlaygroundHTML source
<div class="sl-stack" id="multiple-accordion">
<details class="sl-details" open>
<summary>First answer</summary>
<p>This answer can remain open while another is expanded.</p>
</details>
<details class="sl-details" open>
<summary>Second answer</summary>
<p>This answer can remain open while another is expanded.</p>
</details>
<details class="sl-details">
<summary>Third answer</summary>
<p>This answer can remain open while another is expanded.</p>
</details>
</div>Independent exclusive groups
Each group has its own name; an open item in one group does not close the other.
Design
design question 1
A separate name isolates this group.
design question 2
A separate name isolates this group.
Delivery
delivery question 1
A separate name isolates this group.
delivery question 2
A separate name isolates this group.
View HTML / PlaygroundHTML source
<div class="sl-grid sl-md:cols-2 sl-gap-6">
<section class="sl-stack">
<h3 class="sl-text-lg">Design</h3>
<details class="sl-details" name="design-demo" open>
<summary>design question 1</summary>
<p>A separate name isolates this group.</p>
</details>
<details class="sl-details" name="design-demo">
<summary>design question 2</summary>
<p>A separate name isolates this group.</p>
</details>
</section>
<section class="sl-stack">
<h3 class="sl-text-lg">Delivery</h3>
<details class="sl-details" name="delivery-demo" open>
<summary>delivery question 1</summary>
<p>A separate name isolates this group.</p>
</details>
<details class="sl-details" name="delivery-demo">
<summary>delivery question 2</summary>
<p>A separate name isolates this group.</p>
</details>
</section>
</div>Flush, initially closed, with rich content
What can an answer contain?
Links, lists, and ordinary semantic content.
- Keep headings meaningful.
- Keep focus visible.
Can I leave everything closed?
Yes. Omit the open attribute. Exclusive groups also allow their last open item to close.
View HTML / PlaygroundHTML source
<div class="sl-stack sl-gap-0">
<details class="sl-details sl-details--flush">
<summary>What can an answer contain?</summary>
<div class="sl-stack">
<p>Links, lists, and ordinary semantic content.</p>
<ul>
<li>Keep headings meaningful.</li>
<li>Keep focus visible.</li>
</ul>
<a href="/getting-started/">Read the guide →</a>
</div>
</details>
<details class="sl-details sl-details--flush">
<summary>Can I leave everything closed?</summary>
<p>
Yes. Omit the open attribute. Exclusive groups also allow their last open item to
close.
</p>
</details>
</div>Classes beginning with sl- come from StyloftCSS. Examples with demo- classes also use our optional demo extension CSS ↓. Load it after the core to reproduce those details.