Skip to content
GreenSnippets

Accordion with details and summary

A keyboard-accessible FAQ accordion with no JavaScript, including an exclusive group using the name attribute.

HTML
<section aria-labelledby="faq-title">
  <h2 id="faq-title">Frequently asked questions</h2>

  <details name="faq" open>
    <summary>What is included in the free plan?</summary>
    <p>Up to three projects and community support.</p>
  </details>

  <details name="faq">
    <summary>Can I cancel at any time?</summary>
    <p>Yes. You keep access until the end of the billing period.</p>
  </details>
</section>

Example / expected output

Output
<!-- Style the marker with summary::marker or summary { list-style: none; } -->

How it works

<details> and <summary> provide an expand/collapse widget that works with keyboard and screen readers. Giving several <details> the same name makes them exclusive: opening one closes the others (supported in current browsers; older ones simply allow several open).

This snippet has been reviewed but was not executed by an automated test. Test it in your own environment before relying on it.