Navigation
Sidebar
Collapsible app sidebar.
Usage
Wrap the page in SidebarProvider, put a Sidebar next to a SidebarInset and build the menu from groups, rows and optional nested items. Press Ctrl + B (or the trigger) to collapse it to an icon rail; the label of each row appears in a tooltip while it is collapsed. The state is remembered between visits.
When to use
- Apps with more than five destinations, or destinations with sub-pages.
- Tools people stay in all day, where the navigation should always be one click away.
Not for: marketing sites (use a navbar) or a handful of tabs inside one page (use tabs).
Full page and framed
On a full page the sidebar is sticky and as tall as the screen. Add framed to SidebarProvider and give it a height to lay it out inside a card or a docs preview; the inset then scrolls on its own. Below 768px (mobileBreakpoint) the same content opens as an off-canvas sheet.
Off-canvas
collapsible="offcanvas" slides the sidebar away completely instead of leaving a rail. collapsible="none" never collapses on desktop.
API
SidebarProvider
| Prop | Type | Default | Description |
|---|---|---|---|
| open / defaultOpen / onOpenChange | boolean / boolean / (open) => void | defaultOpen: true | Desktop state: expanded or collapsed. |
| storageKey | string | false | 'ui-sidebar' | localStorage key that remembers the state. Wrapped in try/catch; false turns it off. |
| shortcut | boolean | true | Ctrl / Cmd + B toggles. Ignored while typing in a field. |
| mobileBreakpoint | number | 768 | Viewport width under which the sidebar is a sheet. |
| framed | boolean | false | Lay out inside a fixed-height container instead of the page. |
Sidebar
| Prop | Type | Default | Description |
|---|---|---|---|
| side | 'left' | 'right' | 'left' | Edge it sits on. |
| collapsible | 'icon' | 'offcanvas' | 'none' | 'icon' | What collapsing does. |
SidebarMenuButton
| Prop | Type | Default | Description |
|---|---|---|---|
| isActive | boolean | false | Current page: highlighted, aria-current="page". |
| tooltip | ReactNode | — | Shown to the right while the sidebar is collapsed. |
| size | 'default' | 'lg' | 'default' | 36px row, or a 48px row for a workspace or account. |
| asChild | boolean | false | Render the child element, e.g. a Next.js Link. |
Layout: SidebarHeader, SidebarContent (scrolls), SidebarFooter, SidebarGroup, SidebarGroupLabel, SidebarMenu, SidebarMenuItem, SidebarMenuBadge, SidebarTrigger, SidebarInset. Nested items: SidebarMenuSub with a SidebarMenuSubTrigger and a SidebarMenuSubContent of SidebarMenuSubItem / SidebarMenuSubButton. useSidebar() returns open, collapsed, isMobile and toggle.
Keyboard
| Key | Action |
|---|---|
| Ctrl / ⌘ + B | Collapse or expand the sidebar (opens the sheet on mobile). |
| Tab | Moves through the rows; closed nested items are skipped. |
| Enter / Space | Activates a row or opens a nested group. |
| Esc | Closes the mobile sheet. |
Accessibility
- An aside landmark with a label; on mobile a modal sheet with a title.
- The trigger reports aria-expanded; nested groups use aria-expanded and aria-controls.
- While collapsed each icon-only row keeps its accessible name (its label is clipped, not removed) and shows a tooltip on hover and keyboard focus.
Motion
- The width animates on the smooth spring and never on first load; labels are clipped, so nothing reflows while it moves.
- Nested items open with a height spring; the chevron turns on the snappy spring.
- Reduced motion keeps the state change and drops the movement.