---
title: "Sidebar"
description: "A composable app sidebar: a fixed panel that slides out or shrinks to an icon rail on desktop, and a Drawer on phones."
url: https://gelatinui.com/components/sidebar
markdown_url: https://gelatinui.com/components/sidebar.md
access: free
install: "npx shadcn@latest add @gelatin-ui/sidebar"
registry_item: https://gelatinui.com/r/sidebar.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Sidebar

> A composable app sidebar: a fixed panel that slides out or shrinks to an icon rail on desktop, and a Drawer on phones.

Page: https://gelatinui.com/components/sidebar

## When to use it

Best for: The main navigation of an app: a panel that collapses on desktop and becomes a Drawer on a phone.

- Use it for the main navigation of an app, with groups, rows, and child pages.
- Use `collapsible="icon"` to keep a 48px icon rail. Use `offcanvas` to slide the panel out, or `none` to keep it open.
- Use `variant` to set the look: `sidebar`, `floating`, or `inset`.
- Use `side="right"` for a details panel at the inline end.
- Use `contained` for a Sidebar inside a block of a page, not on the screen edge.

## When not to use it

- For the main views of a phone app, use a [Thumb Bar](https://gelatinui.com/components/thumb-bar.md).
- For a short panel that opens over the page, use a [Drawer](https://gelatinui.com/components/drawer.md).
- For a list of actions that opens from a button, use a [Menu](https://gelatinui.com/components/menu.md).

## Notes for agents

- Wrap the `Sidebar` and the `SidebarInset` in a `SidebarProvider`. `useSidebar` works only inside the provider.
- Each change writes the cookie `sidebar_state`. Read it on the server and pass `defaultOpen` to keep the state.
- Read the cookie each time the layout mounts: in a router guard that runs on every navigation (TanStack `beforeLoad`, a Next.js layout), not in a cached loader. A cached value opens a folded Sidebar again after a visit to another layout.
- Give each Sidebar of an app its own `cookie` name, so folding one does not fold the other.
- Set `cookie={false}` to turn the cookie off.
- Under 768px the Sidebar is a Drawer. A press on a page row closes it; rows that open a menu or a fold keep it open.
- Give each `SidebarMenuButton` a `tooltip` in `collapsible="icon"`. The label is gone in the rail, and in the open panel the tip shows the full label when the row cuts it off.
- Do not set `id` on `Sidebar`. The provider makes the id that the trigger needs.
- Pass `keyboardShortcut={false}` in an app with a text editor, where ⌘B means bold.
- Put the icon first and the label in a `span` last, so the label truncates.

## Anatomy

```text
Sidebar
├─ SidebarProvider (0..n)
├─ SidebarTrigger (0..n)
├─ SidebarRail (0..n)
├─ SidebarInset (0..n)
├─ SidebarInput (0..n)
├─ SidebarHeader (0..n)
├─ SidebarFooter (0..n)
├─ SidebarSeparator (0..n)
├─ SidebarContent (0..n)
├─ SidebarGroup (0..n)
├─ SidebarGroupContent (0..n)
├─ SidebarMenu (0..n)
├─ SidebarMenuItem (0..n)
├─ SidebarMenuBadge (0..n)
├─ SidebarMenuSkeleton (0..n)
├─ SidebarMenuSub (0..n)
└─ SidebarMenuSubItem (0..n)
```

## API reference

### Sidebar

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `side` | `"left" \| "right"` | "left" | The edge: `left` is the inline start, `right` the inline end (they swap on a right-to-left page). |
| `variant` | `"floating" \| "inset" \| "sidebar"` | "sidebar" | `sidebar`: a column with a border. `floating`: a card with 8px around it. `inset`: the page is a card beside it. |
| `collapsible` | `"icon" \| "none" \| "offcanvas"` | "offcanvas" | `offcanvas`: it slides out. `icon`: it shrinks to a 48px icon rail. `none`: it never collapses. |

### SidebarTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### SidebarMenuButton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"default" \| "lg" \| "sm"` | "default" |  |
| `variant` | `"default" \| "outline"` | "default" |  |
| `isActive` | `boolean` | false | The current page: the raised chip and `data-active`. Also set `aria-current="page"` on a link. |
| `tooltip` | `string \| (Omit` |  | The row tooltip: a string, or the `TooltipContent` props. It shows at once (no delay), in the one tooltip that glides between rows: on the icon rail always, in the open panel only while the label is cut off. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### SidebarMenuSkeleton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `showIcon` | `boolean` | false | Show a 16px square in the icon place. |

### SidebarMenuSubButton

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `"md" \| "sm"` | "md" | `md` (default) 28px, `sm` 24px. Text is 14px in both. |
| `isActive` | `boolean` | false | The current page: the raised chip. Also set `aria-current="page"`. |
| `tooltip` | `string \| (Omit` |  | The full label, shown in the row tooltip while the row cuts it off. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| SidebarProvider | `sidebar-wrapper` | `data-variant` | `--sidebar-width`, `--sidebar-width-icon` |  |
| Sidebar | `sidebar` | `data-collapsible`, `data-moving`, `data-side`, `data-sidebar`, `data-state`, `data-swipe-direction`, `data-variant` | `--motion-fade-exit`, `--motion-sheet`, `--sidebar-inner-width`, `--sidebar-width`, `--sidebar-width-icon` | `motion-timing` |
| SidebarTrigger | `sidebar-trigger` |  |  |  |
| SidebarRail | `sidebar-rail` | `data-collapsible`, `data-side` |  |  |
| SidebarInset | `sidebar-inset` | `data-side`, `data-state`, `data-variant` |  | `motion-timing` |
| SidebarInput | `sidebar-input` | `data-collapsible` |  |  |
| SidebarHeader | `sidebar-header` |  |  |  |
| SidebarFooter | `sidebar-footer` |  |  |  |
| SidebarSeparator | `sidebar-separator` |  |  |  |
| SidebarContent | `sidebar-content` | `data-collapsible` |  | `scroll-fade` |
| SidebarGroup | `sidebar-group` |  |  |  |
| SidebarGroupContent | `sidebar-group-content` |  |  |  |
| SidebarMenu | `sidebar-menu` |  |  |  |
| SidebarMenuItem | `sidebar-menu-item` |  |  |  |
| SidebarMenuBadge | `sidebar-menu-badge` | `data-active`, `data-size`, `data-state` |  | `motion-timing`, `status-colors` |
| SidebarMenuSkeleton | `sidebar-menu-skeleton` | `data-width` |  |  |
| SidebarMenuSub | `sidebar-menu-sub` | `data-collapsible` |  |  |
| SidebarMenuSubItem | `sidebar-menu-sub-item` |  |  |  |

## Usage

Wrap the `Sidebar` and the `SidebarInset` in a `SidebarProvider`. The provider holds the open state, the cookie, and the keyboard shortcut.

```tsx title="app-shell.tsx"
import { TrayIcon } from "@phosphor-icons/react/ssr";
import type { ReactNode } from "react";

import {
  Sidebar,
  SidebarContent,
  SidebarInset,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarProvider,
  SidebarTrigger,
} from "@/components/ui/sidebar";

export function AppShell({ children }: { children: ReactNode }) {
  return (
    <SidebarProvider>
      <Sidebar>
        <SidebarContent>
          <SidebarMenu>
            <SidebarMenuItem>
              <SidebarMenuButton isActive render={<a href="/inbox" />}>
                <TrayIcon />
                <span>Inbox</span>
              </SidebarMenuButton>
            </SidebarMenuItem>
          </SidebarMenu>
        </SidebarContent>
      </Sidebar>
      <SidebarInset>
        <SidebarTrigger />
        {children}
      </SidebarInset>
    </SidebarProvider>
  );
}
```

## Compose

Build it with:

- [Frame](https://gelatinui.com/components/frame.md): Groups the fields of one section, with Save in its footer.
- [Field](https://gelatinui.com/components/field.md): Names each control and shows its help or error text.
- [Switch](https://gelatinui.com/components/switch.md): Turns one setting on or off at once.
- [Select](https://gelatinui.com/components/select.md): Picks one value from a short list.
- [Button](https://gelatinui.com/components/button.md): Saves the section or opens a dialog.
- [Toast](https://gelatinui.com/components/toast.md): Confirms the save.
- [Badge](https://gelatinui.com/components/badge.md): Shows a count next to a link.
- [Avatar](https://gelatinui.com/components/avatar.md): Shows the signed-in person in the footer.

Rules:

- Touch targets (`touch-targets`): Give every control a hit area of at least 44 px on touch screens, even when it looks smaller.
- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Name every control (`label-every-control`): Give every field a visible `Label` (or a `Field`), and every icon button a `Tooltip` or an `aria-label`.
- Labels real apps use (`real-labels`): Write the button and menu labels that real apps use ("Create API key", "Invite members"), with no "…" at the end.

Patterns: `gelatin://patterns/settings-page`, `gelatin://patterns/app-sidebar`

## Add it

```bash
npx shadcn@latest add @gelatin-ui/sidebar
```

It adds 40 registry items: 36 files, 6441 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `clsx`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Button](https://gelatinui.com/components/button.md)
- [Drawer](https://gelatinui.com/components/drawer.md)
- [Input](https://gelatinui.com/components/input.md)
- [Kbd](https://gelatinui.com/components/kbd.md)
- [Separator](https://gelatinui.com/components/separator.md)
- [Skeleton](https://gelatinui.com/components/skeleton.md)
- [Tooltip](https://gelatinui.com/components/tooltip.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Drawer](https://gelatinui.com/components/drawer.md)
- [Thumb Bar](https://gelatinui.com/components/thumb-bar.md)
- [Menu](https://gelatinui.com/components/menu.md)

## Keyboard

| Keys | Action |
| --- | --- |
| ⌘B, Ctrl+B | Opens or closes the Sidebar. `keyboardShortcut` changes the letter. |
| Enter, Space | On `SidebarTrigger`: opens or closes the Sidebar. |
| Escape | Phone Drawer: closes the Drawer. |

## Accessibility

`SidebarTrigger` is a button that controls the panel, and Ctrl+B or ⌘B toggles it. Its tooltip shows the keys, and `aria-keyshortcuts` names them.

Under 768px the panel is a Drawer, so it traps focus and Escape closes it.

In `collapsible="icon"` the label is gone. Give each `SidebarMenuButton` a `tooltip`.

## Motion

| Part | Motion |
| --- | --- |
| Fold | sheet · 300ms · ease-panel (0.2, 0.4, 0.2, 1) · slides with `transform`; the page takes its room at once |
