Skip to content
Introducing StyloftCSS 0.1 / A small foundation for your next big idea. Meet the framework
Essentials

Accordions

Native disclosures with familiar keyboard interaction. No state library required.

CSS only6 examplesKeyboard friendly HTML

Frequently asked questions

Independent details elements allow several answers to remain open.

Live preview
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
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground23 lines · UTF-8

A single disclosure

Live preview
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
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground7 lines · UTF-8

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.

Live preview
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
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground23 lines · UTF-8

Several open at the same time

Omit name to let readers compare multiple answers.

Live preview
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
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground14 lines · UTF-8

Independent exclusive groups

Each group has its own name; an open item in one group does not close the other.

Live preview

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
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground24 lines · UTF-8

Flush, initially closed, with rich content

Live preview
What can an answer contain?

Links, lists, and ordinary semantic content.

  • Keep headings meaningful.
  • Keep focus visible.
Read the guide →
Can I leave everything closed?

Yes. Omit the open attribute. Exclusive groups also allow their last open item to close.

View HTML / PlaygroundHTML source
example.htmlHTML
<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>
HTML source · enable JavaScript for the playground20 lines · UTF-8

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.