Collapse

A section that opens and closes. Stack them and you have an accordion, which is what Kobalte's Accordion renders: a heading with a trigger, then a region.

alpha The class names and states here are stable. The look is not: these styles can change in a minor release, without a major version bump.

ClassDoes what
collapseOne section, with a rule under it
collapse-titleThe trigger row
collapse-contentThe panel

Basic

<details> gives you this with no script. Kobalte gives you keyboard navigation across the whole stack, and marks the open item data-expanded.

<details class="collapse" open>
  <summary class="collapse-title">What is included? <span>−</span></summary>
  <div class="collapse-content">Everything in the free plan, plus unlimited projects.</div>
</details>
<details class="collapse">
  <summary class="collapse-title">Can I cancel? <span>+</span></summary>
  <div class="collapse-content">Any time, from the billing page.</div>
</details>

Kobalte's Trigger has no role of its own, so the binding reaches it as the button inside the heading that precedes a role="region". That is the most positional selector in the Kobalte layer.

Composition

Common ways to put this together with other components. The general rules are on Composition.

Questions and answers

A stack of questions under a heading; each answer is prose.

Same markup in both builds
<section>
  <div class="prose"><h2>Questions</h2></div>
  <details class="collapse" open>
    <summary class="collapse-title">How long does it take? <span>−</span></summary>
    <div class="collapse-content prose">
      <p>Most projects launch in two to six weeks.</p>
      <ul><li>One call to scope it</li><li>A demo before launch</li></ul>
    </div>
  </details>
  <details class="collapse">
    <summary class="collapse-title">Can my team edit it? <span>+</span></summary>
    <div class="collapse-content prose"><p>Yes, from a browser, with no code.</p></div>
  </details>
</section>

Advanced options in a form

Settings most people never need fold away under the ones they do.

Same markup in both builds
<form class="card">
  <label class="label"><p>Site name</p><input class="input" /></label>
  <details class="collapse" open>
    <summary class="collapse-title">Advanced options <span>−</span></summary>
    <div class="collapse-content">
      <label class="label"><p>Custom domain</p><input class="input" placeholder="www.example.com" /></label>
    </div>
  </details>
  <footer class="card-actions flex" style="justify-content: end">
    <button class="btn">Save</button>
  </footer>
</form>