Base · Navigation
Sidebar
The vertical navigation panel of an application, with grouped links and optional collapse.
Props
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarInset,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
} from "@/components/ui/sidebar"
import { PackageIcon, RouteIcon } from "lucide-react"
<SidebarProvider>
<Sidebar>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Operations</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton isActive render={<a href="/shipments" />}>
<PackageIcon />
<span>Shipments</span>
</SidebarMenuButton>
</SidebarMenuItem>
<SidebarMenuItem>
<SidebarMenuButton render={<a href="/routes" />}>
<RouteIcon />
<span>Routes</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
</Sidebar>
<SidebarInset>{/* page */}</SidebarInset>
</SidebarProvider>Overview
The sidebar holds an application's primary navigation along one edge of the window. It is a set of parts (header, groups, menu, footer) that you compose, wrapped in a provider that tracks whether it is expanded. On small screens it turns into a sheet.
When to use
- As the main navigation of an application with more than a few sections.
- When destinations are grouped or nested and need labels beside their icons.
- When users switch sections often and benefit from navigation that is always visible.
When not to use
- For sites with a few top-level pages and a horizontal header: use a Navigation menu.
- For a temporary panel of details or a form: use a Sheet.
- For switching views inside one page: use Tabs.
- For commands rather than destinations: use a Menubar or Dropdown menu.
Anatomy
Provider
Wraps the layout, holds the open state and registers the toggle shortcut.
Sidebar
The panel itself. Fixed to the left or right edge, 16rem wide.
Header and footer
Pinned areas for a workspace switcher or account menu.
Content
The scrolling area between them.
Group
A section with an optional label and action.
Menu, item and button
A list of destinations. The button holds an icon and a label and can be marked active.
Badge, action and sub-menu
Optional extras on a menu item: a count, a trailing button, nested links.
Trigger and rail
A button, and a thin strip on the edge, that toggle the sidebar.
Props
The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "sm" | "lg" | default | Height of a menu button. Set on SidebarMenuButton. |
| variant | "default" | "outline" | default | Style of a menu button. `outline` gives it a background and a hairline border. |
| groupLabel | string | Operations | Heading of the group. Passed as children of SidebarGroupLabel. |
| isActive | boolean | – | Marks a SidebarMenuButton as the current page. |
| tooltip | string | – | On SidebarMenuButton, the label shown in a tooltip when the sidebar is collapsed to icons. |
| collapsible | "offcanvas" | "icon" | "none" | offcanvas | On Sidebar: slide off screen, shrink to icons, or never collapse. |
| side | "left" | "right" | left | On Sidebar: the edge it is attached to. |
| onOpenChange | function | – | On SidebarProvider: called when the sidebar expands or collapses. |
States
- Expanded
- Full width with icons and labels.
- Collapsed
- Off screen, or icon-only with tooltips, depending on the collapsible prop.
- Mobile
- Hidden by default; opens as a sheet over the page.
- Item hover
- Accent background on the menu button.
- Item active
- Accent background and medium font weight.
Accessibility
Role: navigation
| Keys | Action |
|---|---|
| Tab/Shift+Tab | Moves through the links and buttons in the sidebar. |
| Enter | Follows the focused link. |
| Cmd+B/Ctrl+B | Expands or collapses the sidebar. |
| Escape | On mobile, closes the sheet. |
- Render menu buttons as links (render={<a href=… />}) when they navigate, and set aria-current="page" on the active one.
- In icon-only mode every button needs the tooltip prop so its label stays available.
- The toggle button has the accessible name “Toggle Sidebar”.
- Wrap the sidebar in a nav element or give it a label so it is exposed as a landmark.
Design tokens
Change any of these in Foundations and this component follows, in every language.
Platform notes
- HTML / JS
- Planned
- Not built in HTML / JS yet.
- React
- Stable
- Matches the contract with no platform differences.
- React Native
- Not available
- Use the navigation library's drawer navigator on tablets and a bottom tab bar on phones.
- Swift (SwiftUI)
- Planned
- Not built in Swift yet.
- Godot
- Planned
- Not built in Godot yet.
- Vue
- Draft
- Usage snippet only; menu buttons use as-child in place of React's render prop.
- Svelte
- Draft
- Usage snippet only (Svelte 5); menu buttons use a child snippet in place of React's render prop.
- Solid
- Draft
- Usage snippet only; menu buttons use the as prop in place of React's render prop.