---
title: "Collapsible"
description: "Collapsible component - expandable content sections using <details>/<summary>."
slug: "collapsible"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="collapsible" title="Collapsible" component="collapsible">
  An interactive panel that expands/collapses content. Built on native <code>&lt;details&gt;</code> with animated transitions.
</PageHeader>

<SkillPanel component="collapsible">
  <SkillField label="Native basis">
<SkillText><code>&lt;details&gt;</code> element providing native expand/collapse behavior with animated transitions.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details" title="native disclosure widget"><code>&lt;details&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary" title="visible heading/trigger"><code>&lt;summary&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/::details-content" title="pseudo-element for content animation"><code>::details-content</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@starting-style" title="entry animation starting values"><code>@starting-style</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.collapsible</code>
    <code>.collapsible-trigger</code>
    <code>.collapsible-chevron</code>
    <code>.collapsible-content</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Accessibility">
<SkillText dense>• <code>&lt;details&gt;</code>/<code>&lt;summary&gt;</code> is natively accessible - keyboard and screen reader support built in</SkillText>
  <SkillText dense>• No additional ARIA attributes needed</SkillText>
  <p class="text-muted-foreground m-0">• Summary text should clearly describe the hidden content</p>
  </SkillField>
</SkillPanel>

```html example label="Basic" hint="Simple collapsible with a trigger and content."
<details class="collapsible">
  <summary class="collapsible-trigger">
    <span>Can I use this?</span>
    <svg
      class="collapsible-chevron"
      aria-hidden="true"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
    >
      <path d="m6 9 6 6 6-6"></path>
    </svg>
  </summary>
  <div class="collapsible-content">
    <p>Yes, it's free to use.</p>
  </div>
</details>
```

```html example label="Open by Default" hint="Use the open attribute to start expanded."
<details class="collapsible" open>
  <summary class="collapsible-trigger">
    <span>What is included?</span>
    <svg
      class="collapsible-chevron"
      aria-hidden="true"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
    >
      <path d="m6 9 6 6 6-6"></path>
    </svg>
  </summary>
  <div class="collapsible-content">
    <p>Every component, the theme presets and the documentation - it starts open because of the open attribute.</p>
  </div>
</details>
```

```html example label="Multiple Sections" hint="Stack multiple collapsibles for a settings-style panel."
<div style="width: 100%; max-width: 24rem; display: flex; flex-direction: column; gap: 0.5rem">
  <details class="collapsible">
    <summary class="collapsible-trigger">
      <span>Appearance</span>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="m6 9 6 6 6-6" />
      </svg>
    </summary>
    <div class="collapsible-content">
      <p class="m-0">Customize the look and feel of your workspace.</p>
    </div>
  </details>
  <details class="collapsible">
    <summary class="collapsible-trigger">
      <span>Notifications</span>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="m6 9 6 6 6-6" />
      </svg>
    </summary>
    <div class="collapsible-content">
      <p class="m-0">Manage your notification preferences.</p>
    </div>
  </details>
  <details class="collapsible">
    <summary class="collapsible-trigger">
      <span>Privacy</span>
      <svg
        xmlns="http://www.w3.org/2000/svg"
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
      >
        <path d="m6 9 6 6 6-6" />
      </svg>
    </summary>
    <div class="collapsible-content">
      <p class="m-0">Control your privacy and data sharing settings.</p>
    </div>
  </details>
</div>
```

```html example label="Colors" hint="data-variant sets the surface: muted, primary, neutral, ghost (no border) - and highlight, plain while closed and primary once open. The heading, the marker and the content all follow the surface's text color."
<div class="stack gap-2" style="width: 100%; max-width: 26rem">
  <details class="collapsible" data-variant="muted" data-marker="arrow">
    <summary class="collapsible-trigger">Muted</summary>
    <div class="collapsible-content"><p class="m-0">A soft surface, no border.</p></div>
  </details>
  <details class="collapsible" data-variant="primary" data-marker="arrow" open>
    <summary class="collapsible-trigger">Primary</summary>
    <div class="collapsible-content"
      ><p class="m-0">The primary surface - content text is the foreground, softened.</p></div
    >
  </details>
  <details class="collapsible" data-variant="neutral" data-marker="arrow">
    <summary class="collapsible-trigger">Neutral</summary>
    <div class="collapsible-content"><p class="m-0">A charcoal surface, the same in both modes.</p></div>
  </details>
  <details class="collapsible" data-variant="ghost" data-marker="arrow">
    <summary class="collapsible-trigger">Ghost</summary>
    <div class="collapsible-content"><p class="m-0">No surface, no border - the hover tint still shows.</p></div>
  </details>
  <details class="collapsible" data-variant="highlight" data-marker="plus">
    <summary class="collapsible-trigger">Highlight when open</summary>
    <div class="collapsible-content"
      ><p class="m-0">Plain while closed, primary once open - the color change animates.</p></div
    >
  </details>
</div>
```

```html example label="Custom colors" hint="Set background and color on the .collapsible itself - the hover tint, the marker and the content text derive from its color, so any palette works."
<div class="stack gap-2" style="width: 100%; max-width: 26rem">
  <details
    class="collapsible"
    data-marker="arrow"
    style="background: oklch(0.93 0.06 190); color: oklch(0.32 0.08 200); border-color: oklch(0.8 0.08 190)"
    open
  >
    <summary class="collapsible-trigger">Teal</summary>
    <div class="collapsible-content"><p class="m-0">Every shade of this panel comes from two declarations.</p></div>
  </details>
  <details
    class="collapsible"
    data-marker="plus"
    style="background: linear-gradient(120deg, oklch(0.55 0.22 300), oklch(0.6 0.2 350)); color: white; border: 0"
  >
    <summary class="collapsible-trigger">Gradient</summary>
    <div class="collapsible-content"><p class="m-0">A gradient surface with white text.</p></div>
  </details>
</div>
```

```html example label="Bold headings" hint="data-size scales the heading: sm, md (default), lg semibold, xl bold."
<div class="stack gap-2" style="width: 100%; max-width: 26rem">
  <details class="collapsible" data-size="lg" data-marker="arrow" open>
    <summary class="collapsible-trigger">Large, semibold</summary>
    <div class="collapsible-content"><p class="m-0">The content keeps its size - only the heading scales.</p></div>
  </details>
  <details class="collapsible" data-size="xl" data-marker="arrow">
    <summary class="collapsible-trigger">Extra large, bold</summary>
    <div class="collapsible-content"><p class="m-0">For page-level sections.</p></div>
  </details>
  <details class="collapsible" data-size="sm" data-marker="arrow">
    <summary class="collapsible-trigger">Small</summary>
    <div class="collapsible-content"><p class="m-0">For dense panels.</p></div>
  </details>
</div>
```

```html example label="Icons and emojis" hint="A .collapsible-icon in front of the heading holds an icon or an emoji in a fixed box, so headings line up."
<div class="stack gap-2" style="width: 100%; max-width: 26rem">
  <details class="collapsible" data-marker="arrow">
    <summary class="collapsible-trigger"
      ><span class="collapsible-icon" aria-hidden="true"><i data-lucide="shield-check"></i></span>Security</summary
    >
    <div class="collapsible-content"><p class="m-0">Two-factor authentication and active sessions.</p></div>
  </details>
  <details class="collapsible" data-marker="arrow">
    <summary class="collapsible-trigger"
      ><span class="collapsible-icon" aria-hidden="true"><i data-lucide="credit-card"></i></span>Billing</summary
    >
    <div class="collapsible-content"><p class="m-0">Plan, invoices and payment methods.</p></div>
  </details>
  <details class="collapsible" data-marker="arrow">
    <summary class="collapsible-trigger"><span class="collapsible-icon" aria-hidden="true">🎨</span>Appearance</summary>
    <div class="collapsible-content"><p class="m-0">Theme, density and fonts.</p></div>
  </details>
  <details class="collapsible" data-marker="arrow">
    <summary class="collapsible-trigger"
      ><span class="collapsible-icon" aria-hidden="true">🔔</span>Notifications</summary
    >
    <div class="collapsible-content"><p class="m-0">Email, push and in-app.</p></div>
  </details>
</div>
```

```html example label="Arrow and plus markers" hint="No icon markup needed: data-marker='arrow' draws a chevron that turns up, 'plus' a + that becomes a -. data-marker-position='start' puts the marker before the heading."
<div class="grid gap-2" style="width: 100%; max-width: 34rem; grid-template-columns: 1fr 1fr">
  <details class="collapsible" data-marker="arrow" open>
    <summary class="collapsible-trigger">Arrow</summary>
    <div class="collapsible-content"><p class="m-0">Open: the arrow points up.</p></div>
  </details>
  <details class="collapsible" data-marker="plus" open>
    <summary class="collapsible-trigger">Plus</summary>
    <div class="collapsible-content"><p class="m-0">Open: the plus is a minus.</p></div>
  </details>
  <details class="collapsible" data-marker="arrow" data-marker-position="start">
    <summary class="collapsible-trigger">Arrow at the start</summary>
    <div class="collapsible-content"><p class="m-0">Like a file tree.</p></div>
  </details>
  <details class="collapsible" data-marker="plus" data-marker-position="start">
    <summary class="collapsible-trigger">Plus at the start</summary>
    <div class="collapsible-content"><p class="m-0">Like a FAQ.</p></div>
  </details>
</div>
```

```html example label="Custom open/close signs" hint="Your own glyph: a .collapsible-chevron turns 180° (90° with data-turn='quarter', for a chevron-right) - or put two elements in the heading, .collapsible-when-closed and .collapsible-when-open, and the right one shows."
<div class="stack gap-2" style="width: 100%; max-width: 26rem">
  <details class="collapsible">
    <summary class="collapsible-trigger"
      >Quarter turn <i data-lucide="chevron-right" class="collapsible-chevron" data-turn="quarter"></i
    ></summary>
    <div class="collapsible-content"><p class="m-0">A chevron-right that turns down when open.</p></div>
  </details>
  <details class="collapsible">
    <summary class="collapsible-trigger"
      ><span class="collapsible-icon" aria-hidden="true"
        ><span class="collapsible-when-closed">📁</span><span class="collapsible-when-open">📂</span></span
      >Projects</summary
    >
    <div class="collapsible-content"><p class="m-0">The folder opens with the panel.</p></div>
  </details>
  <details class="collapsible">
    <summary class="collapsible-trigger"
      >Release notes <span class="collapsible-when-closed text-sm">Show</span
      ><span class="collapsible-when-open text-sm">Hide</span></summary
    >
    <div class="collapsible-content"><p class="m-0">Words instead of an icon.</p></div>
  </details>
</div>
```

```html example label="Right to left" hint="Everything is logical: in dir='rtl' the icon leads on the right, the marker sits on the left, a quarter-turned chevron mirrors."
<div class="stack gap-2" dir="rtl" lang="ar" style="width: 100%; max-width: 26rem">
  <details class="collapsible" data-marker="arrow" open>
    <summary class="collapsible-trigger"
      ><span class="collapsible-icon" aria-hidden="true"><i data-lucide="shield-check"></i></span>الأمان</summary
    >
    <div class="collapsible-content"><p class="m-0">المصادقة الثنائية والجلسات النشطة.</p></div>
  </details>
  <details class="collapsible" data-marker="plus" data-variant="muted">
    <summary class="collapsible-trigger"><span class="collapsible-icon" aria-hidden="true">🎨</span>المظهر</summary>
    <div class="collapsible-content"><p class="m-0">السمة والكثافة والخطوط.</p></div>
  </details>
  <details class="collapsible">
    <summary class="collapsible-trigger"
      >ملاحظات الإصدار <i data-lucide="chevron-right" class="collapsible-chevron" data-turn="quarter"></i
    ></summary>
    <div class="collapsible-content"><p class="m-0">سهم يدور ربع دورة.</p></div>
  </details>
</div>
```

```html example label="Density" hint="Set data-density on the component root to scale its internal whitespace. A whitespace policy, not a zoom: only gaps and padding scale (ratio 0.75 / 1 / 1.25), typography and fixed dimensions stay identical. comfortable matches the unsized default." previewStyle="flex-direction:column;align-items:stretch;gap:1rem;"
<div style="width: 100%; max-width: 24rem">
  <p class="demo-label">Compact</p>
  <details class="collapsible" open data-density="compact">
    <summary class="collapsible-trigger"
      ><span>Trigger padding shrinks</span
      ><svg
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <path d="m6 9 6 6 6-6" /></svg
    ></summary>
    <div class="collapsible-content"
      ><p class="m-0">The trigger and content paddings scale - the copy stays exactly the same.</p></div
    >
  </details>
  <p class="demo-label" style="margin-top: 1rem">Comfortable</p>
  <details class="collapsible" open data-density="comfortable">
    <summary class="collapsible-trigger"
      ><span>Identical to the default</span
      ><svg
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <path d="m6 9 6 6 6-6" /></svg
    ></summary>
    <div class="collapsible-content"
      ><p class="m-0">The trigger and content paddings scale - the copy stays exactly the same.</p></div
    >
  </details>
  <p class="demo-label" style="margin-top: 1rem">Spacious</p>
  <details class="collapsible" open data-density="spacious">
    <summary class="collapsible-trigger"
      ><span>Trigger padding grows</span
      ><svg
        class="collapsible-chevron"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
        stroke-linejoin="round"
        aria-hidden="true"
      >
        <path d="m6 9 6 6 6-6" /></svg
    ></summary>
    <div class="collapsible-content"
      ><p class="m-0">The trigger and content paddings scale - the copy stays exactly the same.</p></div
    >
  </details>
</div>
```

<StatesSection>
  <p class="text-sm text-muted-foreground">Machine contract - verified against <a class="link" href="../schemas/collapsible.schema.json"><code>collapsible.schema.json</code></a> by <code>bun run verify</code>:</p>

```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | `true`, `false` | `false` | Content revealed - native `<details open>` (panel ⇄ clicking the summary). |
```

</StatesSection>

<SourceFiles component="collapsible" section="css">
  <SourceNote for="css">Styles for the collapsible component. Uses design tokens for colors, spacing, and radius.</SourceNote>
</SourceFiles>

</DocPage>
