---
title: "Sidebar"
description: "Sidebar component - collapsible side navigation panel."
slug: "sidebar"
---

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

<DocPage meta={meta}>

<PageHeader slug="sidebar" title="Sidebar" component="sidebar">
  A composable, themeable application sidebar with collapsible state, mobile sheet overlay, collapsible groups, submenus, badges, and keyboard shortcut (Cmd+B).
</PageHeader>

<SkillPanel component="sidebar">
  <SkillField label="Native basis">
<SkillText><code>&lt;aside&gt;</code> + <code>&lt;nav&gt;</code> + <code>&lt;dialog&gt;</code> for a full application sidebar with collapsible state, mobile overlay, collapsible groups, and submenus.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside" title="complementary content landmark"><code>&lt;aside&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav" title="navigation landmark"><code>&lt;nav&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog" title="native modal for mobile overlay"><code>&lt;dialog&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details" title="collapsible groups and submenus"><code>&lt;details&gt; / &lt;summary&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@starting-style" title="slide-in animation"><code>@starting-style</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible" title="keyboard-only focus ring"><code>:focus-visible</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion" title="suppresses all transitions"><code>prefers-reduced-motion</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.sidebar-layout</code>
    <code>.app-sidebar</code>
    <code>.sidebar-header</code>
    <code>.sidebar-logo</code>
    <code>.sidebar-content</code>
    <code>.sidebar-nav</code>
    <code>.sidebar-link</code>
    <code>.sidebar-badge</code>
    <code>.sidebar-icon</code>
    <code>.sidebar-dot</code>
    <code>.sidebar-section-title</code>
    <code>.sidebar-group</code>
    <code>.sidebar-submenu</code>
    <code>.sidebar-footer</code>
    <code>.sidebar-trigger</code>
    <code>.sidebar-mobile</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Notes">
<p class="text-muted-foreground m-0">• While the mobile sheet is modal, <code>html:has(.sidebar-mobile:modal)</code> sets <code>overflow: hidden</code> + <code>scrollbar-gutter: stable</code> - the page behind cannot scroll and its position is preserved for when the sheet closes (no JS scroll-lock).<br/>• <strong>Auto-collapse</strong>: when the sidebar's row (its container) drops below 24rem the component docks itself to the icon rail and restores above 28rem (hysteresis - no flicker). Trigger clicks, <code>Cmd/Ctrl+B</code> and <code>api.setState()</code> count as deliberate choices and pin the sidebar against the heuristic.</p>
  </SkillField>
</SkillPanel>

<p class="text-sm font-medium mb-2 mt-6">Default</p>

<p class="text-muted-foreground text-sm mb-4">Full sidebar with collapsible groups, submenus, badges, and toggle button. Press <kbd style="font-size:0.6875rem;padding:0.125rem 0.25rem;border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--muted);font-family:var(--font-mono);">⌘B</kbd> to toggle.</p>

```html example height="24" mode="desktop"
<div style="display: flex; width: 100%; height: 100%; border-radius: var(--radius-lg); overflow: hidden">
  <aside class="app-sidebar" id="demo-sidebar" data-state="expanded" style="position: relative; height: 100%">
    <div class="sidebar-header">
      <a class="sidebar-logo" href="#">
        <i data-lucide="command" style="width: 1rem; height: 1rem"></i>
        <span class="sidebar-logo-text">MyApp</span>
      </a>
    </div>
    <div class="sidebar-content">
      <details class="sidebar-group" open>
        <summary>
          <span>Platform</span>
          <i data-lucide="chevron-right" style="width: 0.875rem; height: 0.875rem"></i>
        </summary>
        <nav class="sidebar-nav">
          <a class="sidebar-link" href="#" aria-current="page">
            <i data-lucide="home"></i>
            <span>Dashboard</span>
          </a>
          <a class="sidebar-link" href="#">
            <i data-lucide="inbox"></i>
            <span>Inbox</span>
            <span class="sidebar-badge">12</span>
          </a>
          <details class="sidebar-submenu">
            <summary>
              <i data-lucide="settings"></i>
              <span>Settings</span>
              <i data-lucide="chevron-right" style="width: 0.875rem; height: 0.875rem"></i>
            </summary>
            <nav class="sidebar-nav">
              <a class="sidebar-link" href="#">
                <span>General</span>
              </a>
              <a class="sidebar-link" href="#">
                <span>Team</span>
              </a>
              <a class="sidebar-link" href="#">
                <span>Billing</span>
              </a>
            </nav>
          </details>
        </nav>
      </details>
      <details class="sidebar-group" open>
        <summary>
          <span>Projects</span>
          <i data-lucide="chevron-right" style="width: 0.875rem; height: 0.875rem"></i>
        </summary>
        <nav class="sidebar-nav">
          <a class="sidebar-link" href="#">
            <i data-lucide="folder"></i>
            <span>Design System</span>
          </a>
          <a class="sidebar-link" href="#">
            <i data-lucide="folder"></i>
            <span>Marketing</span>
          </a>
        </nav>
      </details>
    </div>
    <div class="sidebar-footer">
      <span>user@example.com</span>
    </div>
  </aside>
  <div
    style="flex: 1; padding: 1rem; display: flex; align-items: flex-start; gap: 0.5rem; background: var(--background)"
  >
    <button class="sidebar-trigger" data-sidebar-trigger="demo-sidebar" aria-label="Toggle sidebar">
      <i data-lucide="panel-left"></i>
    </button>
    <span class="text-muted-foreground" style="font-size: 0.875rem; padding-top: 0.375rem">Main content area</span>
  </div>
</div>
```

```html example label="Right Side" hint="Add data-side='right' to dock the sidebar to the right edge - the border flips to its left side automatically. The panel rounds only its exposed left corners and stays square (docked) on the right; the trigger sits on the right, next to the panel." height="24" mode="desktop"
<div
  style="
    display: flex;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    overflow: hidden;
  "
>
  <div
    style="
      flex: 1;
      padding: 1rem;
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 0.5rem;
      background: var(--background);
    "
  >
    <span class="text-muted-foreground" style="font-size: 0.875rem; padding-top: 0.375rem">Main content area</span>
    <button class="sidebar-trigger" data-sidebar-trigger="demo-sidebar-right" aria-label="Toggle sidebar">
      <i data-lucide="panel-right"></i>
    </button>
  </div>
  <aside
    class="app-sidebar"
    id="demo-sidebar-right"
    data-side="right"
    data-state="expanded"
    style="position: relative; height: 100%; border-radius: var(--radius-lg) 0 0 var(--radius-lg)"
  >
    <div class="sidebar-header">
      <a class="sidebar-logo" href="#">
        <i data-lucide="command" style="width: 1rem; height: 1rem"></i>
        <span class="sidebar-logo-text">MyApp</span>
      </a>
    </div>
    <div class="sidebar-content">
      <nav class="sidebar-nav">
        <a class="sidebar-link" href="#" aria-current="page">
          <i data-lucide="home"></i>
          <span>Dashboard</span>
        </a>
        <a class="sidebar-link" href="#">
          <i data-lucide="inbox"></i>
          <span>Inbox</span>
        </a>
        <a class="sidebar-link" href="#">
          <i data-lucide="settings"></i>
          <span>Settings</span>
        </a>
      </nav>
    </div>
    <div class="sidebar-footer">
      <span>user@example.com</span>
    </div>
  </aside>
</div>
```

```html example label="Mobile sheet" hint="Below 768px the rail hides; the documented data-sidebar-mobile button opens the <dialog class='sidebar-mobile'> sheet. Booted in Phone mode - click Menu, close with the X or Escape." mode="phone" height="54"
<div style="min-height: 100%">
  <button class="btn" type="button" data-sidebar-mobile="demo-mobile-sheet" style="margin: 1rem">
    <svg
      aria-hidden="true"
      width="16"
      height="16"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
    >
      <path d="M4 6h16M4 12h16M4 18h16" />
    </svg>
    Menu
  </button>
  <dialog class="sidebar-mobile" id="demo-mobile-sheet">
    <button class="sidebar-mobile-close" aria-label="Close">
      <svg
        aria-hidden="true"
        width="14"
        height="14"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        stroke-linecap="round"
      >
        <path d="M18 6 6 18M6 6l12 12" />
      </svg>
    </button>
    <div class="sidebar-header">
      <a class="sidebar-logo" href="#"><span class="sidebar-logo-text">MyApp</span></a>
    </div>
    <div class="sidebar-content">
      <nav class="sidebar-nav">
        <a class="sidebar-link" href="#" aria-current="page"><span>Dashboard</span></a>
        <a class="sidebar-link" href="#"><span>Inbox</span></a>
        <a class="sidebar-link" href="#"><span>Settings</span></a>
      </nav>
    </div>
  </dialog>
</div>
```

```html example label="Icons and emojis" hint="A .sidebar-icon span puts an icon or an emoji in front of any label - links, submenus and the uppercase group headings alike. It is a fixed 1rem box, so every label lines up, and it stays visible on the collapsed rail." height="30" mode="desktop"
<aside
  class="app-sidebar"
  data-state="expanded"
  style="
    position: relative;
    height: auto;
    width: 16rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  "
>
  <div class="sidebar-content">
    <details class="sidebar-group" open>
      <summary>
        <span class="sidebar-icon" aria-hidden="true"><i data-lucide="layout-dashboard"></i></span>
        <span>Workspace</span>
        <i data-lucide="chevron-right"></i>
      </summary>
      <nav class="sidebar-nav">
        <a class="sidebar-link" href="#" aria-current="page"
          ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="house"></i></span><span>Overview</span></a
        >
        <a class="sidebar-link" href="#"
          ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="calendar"></i></span><span>Calendar</span></a
        >
        <details class="sidebar-submenu">
          <summary>
            <span class="sidebar-icon" aria-hidden="true"><i data-lucide="settings"></i></span>
            <span>Settings</span>
            <i data-lucide="chevron-right"></i>
          </summary>
          <nav class="sidebar-nav">
            <a class="sidebar-link" href="#"><span>General</span></a>
            <a class="sidebar-link" href="#"><span>Team</span></a>
          </nav>
        </details>
      </nav>
    </details>
    <details class="sidebar-group" open>
      <summary>
        <span class="sidebar-icon" aria-hidden="true">🗂️</span>
        <span>Projects</span>
        <i data-lucide="chevron-right"></i>
      </summary>
      <nav class="sidebar-nav">
        <a class="sidebar-link" href="#"><span class="sidebar-icon" aria-hidden="true">🚀</span><span>Launch</span></a>
        <a class="sidebar-link" href="#"
          ><span class="sidebar-icon" aria-hidden="true">🎨</span><span>Brand refresh</span></a
        >
        <a class="sidebar-link" href="#"
          ><span class="sidebar-icon" aria-hidden="true">🧪</span><span>Experiments</span></a
        >
      </nav>
    </details>
  </div>
</aside>
```

```html example label="Activity indicators" hint="A .sidebar-dot at the end of a row marks news or activity - on a link, a submenu or a whole group (so a collapsed section still says something inside is new). Colors via data-variant (success / warning / info / destructive), a ping via data-animate='ping', and it pairs with a .sidebar-badge. Name it: role='img' + aria-label. On the collapsed rail the dot moves onto the icon's corner." height="36" mode="desktop"
<div class="flex gap-4 items-start">
  <aside
    class="app-sidebar"
    data-state="expanded"
    style="
      position: relative;
      height: auto;
      width: 16rem;
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
    "
  >
    <div class="sidebar-content">
      <details class="sidebar-group" open>
        <summary>
          <span class="sidebar-icon" aria-hidden="true"><i data-lucide="inbox"></i></span>
          <span>Mail</span>
          <span class="sidebar-dot" role="img" aria-label="New activity"></span>
          <i data-lucide="chevron-right"></i>
        </summary>
        <nav class="sidebar-nav">
          <a class="sidebar-link" href="#"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="mail"></i></span><span>Inbox</span
            ><span class="sidebar-dot" data-variant="info" data-animate="ping" role="img" aria-label="New mail"></span
            ><span class="sidebar-badge">12</span></a
          >
          <a class="sidebar-link" href="#"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="send"></i></span><span>Sent</span></a
          >
          <a class="sidebar-link" href="#"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="triangle-alert"></i></span><span>Spam</span
            ><span class="sidebar-dot" data-variant="warning" role="img" aria-label="Needs review"></span
          ></a>
        </nav>
      </details>
      <details class="sidebar-group" open>
        <summary>
          <span class="sidebar-icon" aria-hidden="true"><i data-lucide="server"></i></span>
          <span>Deploys</span>
          <i data-lucide="chevron-right"></i>
        </summary>
        <nav class="sidebar-nav">
          <a class="sidebar-link" href="#"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="circle-check"></i></span
            ><span>Production</span
            ><span class="sidebar-dot" data-variant="success" role="img" aria-label="Healthy"></span
          ></a>
          <a class="sidebar-link" href="#"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="flame"></i></span><span>Staging</span
            ><span
              class="sidebar-dot"
              data-variant="destructive"
              data-animate="ping"
              role="img"
              aria-label="Failing"
            ></span
          ></a>
        </nav>
      </details>
    </div>
  </aside>
  <div style="width: 14rem">
    <aside
      class="app-sidebar"
      data-state="collapsed"
      style="position: relative; height: auto; border: 1px solid var(--border); border-radius: var(--radius-lg)"
    >
      <div class="sidebar-content">
        <nav class="sidebar-nav">
          <a class="sidebar-link" href="#" aria-label="Inbox"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="mail"></i></span><span>Inbox</span
            ><span class="sidebar-dot" data-variant="info" data-animate="ping" role="img" aria-label="New mail"></span
          ></a>
          <a class="sidebar-link" href="#" aria-label="Sent"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="send"></i></span><span>Sent</span></a
          >
          <a class="sidebar-link" href="#" aria-label="Staging"
            ><span class="sidebar-icon" aria-hidden="true"><i data-lucide="flame"></i></span><span>Staging</span
            ><span class="sidebar-dot" data-variant="destructive" role="img" aria-label="Failing"></span
          ></a>
        </nav>
      </div>
    </aside>
  </div>
</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." height="24" mode="desktop"
<!-- columns are STACKED (full-width rows): the component auto-collapses a rail
     whose row drops below 384px - three side-by-side flex-1 columns inside a
     592px card would each sit under that threshold and dock to the icon rail,
     hiding the entry text (the "text not visible" regression). -->
<div class="stack gap-4">
  <div>
    <p class="demo-label">Compact</p>
    <aside
      class="app-sidebar"
      data-density="compact"
      style="
        position: relative;
        width: auto;
        height: 11rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
      "
      ><div class="sidebar-header"><span class="sidebar-logo-text">App</span></div
      ><div class="sidebar-content"
        ><nav class="sidebar-nav"
          ><a class="sidebar-link" href="#"><span>Dashboard</span></a
          ><a class="sidebar-link" href="#"><span>Inbox</span></a
          ><a class="sidebar-link" href="#"><span>Settings</span></a></nav
        ></div
      ></aside
    >
  </div>
  <div>
    <p class="demo-label">Comfortable</p>
    <aside
      class="app-sidebar"
      data-density="comfortable"
      style="
        position: relative;
        width: auto;
        height: 11rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
      "
      ><div class="sidebar-header"><span class="sidebar-logo-text">App</span></div
      ><div class="sidebar-content"
        ><nav class="sidebar-nav"
          ><a class="sidebar-link" href="#"><span>Dashboard</span></a
          ><a class="sidebar-link" href="#"><span>Inbox</span></a
          ><a class="sidebar-link" href="#"><span>Settings</span></a></nav
        ></div
      ></aside
    >
  </div>
  <div>
    <p class="demo-label">Spacious</p>
    <aside
      class="app-sidebar"
      data-density="spacious"
      style="
        position: relative;
        width: auto;
        height: 11rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
      "
      ><div class="sidebar-header"><span class="sidebar-logo-text">App</span></div
      ><div class="sidebar-content"
        ><nav class="sidebar-nav"
          ><a class="sidebar-link" href="#"><span>Dashboard</span></a
          ><a class="sidebar-link" href="#"><span>Inbox</span></a
          ><a class="sidebar-link" href="#"><span>Settings</span></a></nav
        ></div
      ></aside
    >
  </div>
</div>
```

<StatesSection>
  <p class="text-sm text-muted-foreground m-0 mb-3">Named states via the shared State API, driven per instance through the bound <code>api</code>:</p>
  <ul class="text-sm text-muted-foreground m-0 mb-3 ps-5">
    <li><code>default</code> - expanded (the authored width; <code>setState('default')</code> expands a sidebar written collapsed too)</li>
    <li><code>collapsed</code> - icon-rail width via the documented <code>data-state="collapsed"</code> attribute</li>
  </ul>
  <p class="text-sm text-muted-foreground">The demo element carries <code>data-state-demo</code>; <code>bun run screenshots</code> drives it via <code>el.api.setState(name)</code> and captures <code>screenshots/\{mode\}/sidebar-\{state\}.png</code>.</p>

Machine contract - verified against <a class="link" href="../schemas/sidebar.schema.json"><code>sidebar.schema.json</code></a> by <code>bun run verify</code>:

```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `collapsed` | `boolean` | `true`, `false` | `false` | Rail mode - icon-only width carried by `data-state="collapsed"`. |
```

</StatesSection>

<ApiSection component="sidebar" />

<SourceFiles component="sidebar" section="css">
  <SourceNote for="css">Full sidebar layout with collapsible state, mobile dialog overlay, collapsible groups, submenus, badges, and responsive behavior.</SourceNote>
</SourceFiles>

<SourceFiles component="sidebar" section="js">
  <SourceNote for="js">Toggle collapse, keyboard shortcut (Cmd+B / Ctrl+B), and mobile dialog management.</SourceNote>
</SourceFiles>

</DocPage>
