Sidebar
A composable, themeable and customizable sidebar component.
When to Use
Use Sidebar when you need to:
- Provide persistent application-level navigation across multiple pages
- Organize a large number of navigation items into grouped sections
- Display contextual tools or filters alongside primary content
- Create a collapsible navigation rail that can shrink to icons on desktop
- Build dashboard layouts with multi-level menu hierarchies
When Not to Use
- Simple top-level navigation with few links - use Navigation Menu
- Temporary overlays for settings or details - use Sheet or Drawer
- Mobile-only slide-out panels - use Sheet directly
- In-page section navigation - use Tabs
Default
A collapsible sidebar with smooth natural animation and grouped menu items.
Natural Animation
Smooth ease-out animation that feels organic (400ms).
Rubber Band Animation
Bouncy overshoot effect for a playful, energetic feel (500ms).
Snappy Animation
Quick, minimal easing for a very responsive feel (150ms).
Spring Animation
Subtle spring physics with an iOS-like settle effect (400ms).
Bounce Animation
Pronounced bounce with decay for a dramatic effect (600ms).
Gentle Animation
Smooth and slow for a calming, deliberate feel (500ms).
Animation Variants Overview
Quick reference for all available animation styles and their characteristics.
Smooth ease-out
Bouncy overshoot
Quick & responsive
iOS-like spring
Pronounced bounce
Slow & calming
UX & Design Guidelines
Visual Hierarchy
Use SidebarGroupLabel to create clear category headings. Highlight the active route with isActive on SidebarMenuButton using bg-sidebar-accent. Limit top-level groups to 5-7 for scannability. Use SidebarMenuSub for nested items.
Spacing & Layout
The sidebar defaults to 16rem width and 3rem when collapsed to icons. Use SidebarHeader for branding or user info and SidebarFooter for settings or account actions. Content in SidebarInset automatically adjusts its margin.
Responsive Behavior
On mobile (<768px), the sidebar renders as a Sheet overlay at 18rem width. The SidebarTrigger provides a hamburger-style toggle. Use collapsible="icon" on desktop to allow users to reclaim horizontal space while keeping navigation accessible.
Color & Theming
The sidebar uses dedicated semantic tokens: bg-sidebar, text-sidebar-foreground, and bg-sidebar-accent for hover/active states. The floating variant adds border-sidebar-border with rounded corners and shadow for a detached appearance.
Accessibility
Keyboard Navigation
- Cmd + B (Mac) or Ctrl + B (Windows) — Toggle sidebar open/closed
- Tab — Move focus through sidebar menu items sequentially
- Enter or Space — Activate the focused menu button or trigger
- Escape — Close the mobile sidebar sheet overlay
Screen Reader Support
- The
SidebarTriggerincludessr-onlytext announcing "Toggle Sidebar" - Mobile sheet includes hidden
SheetTitleandSheetDescriptionfor screen readers - Menu items with
asChildpreserve native link semantics and announcements - Active state is conveyed via
data-activeattribute styling
Focus Management
Focus ring uses focus-visible:ring-2 with the ring-sidebar-ring token. When the sidebar opens on mobile, focus is trapped within the Sheet overlay. The SidebarRail uses tabIndex=-1 to prevent accidental focus on the resize handle.
Tooltips in Collapsed State
When collapsed to collapsible="icon", menu buttons with a tooltip prop display their label on hover. Tooltips are automatically hidden when the sidebar is expanded or on mobile.
ARIA Attributes
{/* Sidebar with navigation landmark */}
<Sidebar aria-label="Main navigation">
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Navigation</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton asChild>
<a href="/dashboard">Dashboard</a>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
</Sidebar>
{/* Trigger with accessible label */}
<SidebarTrigger aria-label="Toggle sidebar" />
{/* Menu button with tooltip for collapsed state */}
<SidebarMenuButton tooltip="Dashboard">
<LayoutDashboard />
<span>Dashboard</span>
</SidebarMenuButton>Related Components
API Reference
The Sidebar system is composed of multiple components. Below are the primary props for each.
SidebarProvider
Manages sidebar state, animation, and keyboard shortcut. Wraps the entire sidebar layout.
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultOpen | boolean | true | Default open state of the sidebar (uncontrolled). |
| open | boolean | — | Controlled open state of the sidebar. |
| onOpenChange | (open: boolean) => void | — | Event handler called when open state changes. |
| animation | "natural" | "rubber-band" | "snappy" | "spring" | "bounce" | "gentle" | "natural" | Animation style for sidebar open/close transitions. |
Sidebar
The main sidebar container. Renders as a Sheet on mobile and a fixed panel on desktop.
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "left" | "right" | "left" | Which side of the screen the sidebar appears on. |
| variant | "sidebar" | "floating" | "inset" | "sidebar" | Visual variant of the sidebar container. |
| collapsible | "offcanvas" | "icon" | "none" | "offcanvas" | Collapse behavior: slide off, shrink to icons, or always visible. |
SidebarMenuButton
Interactive menu item button with variant, size, active state, and collapsed-mode tooltip support.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "outline" | "default" | Visual style variant of the menu button. |
| size | "default" | "sm" | "lg" | "default" | The size of the menu button. |
| asChild | boolean | false | Render child as root element, merging props and behavior. |
| isActive | boolean | false | Whether the menu item is in an active/selected state. |
| tooltip | string | TooltipContentProps | — | Tooltip shown when sidebar is collapsed to icon mode. |