Sidebar

The appโ€™s main navigation. It collapses on desktop and becomes a sheet on phones.

The documentation navigation is this exact registry Sidebar. Toggle it here or press Cmd/Ctrl+B, or drag its edge to resize.

On phones, it opens the installed Sheet with modal focus management.

Fig. 1 Toggle the sidebar. This siteโ€™s own navigation is the same component.

When to use it

Use Sidebar for the top level of an app: the sections people move between all day. It keeps their place visible and stays out of the way when collapsed.

For switching views of a single thing, use Tabs. For showing the path to a nested page, add a Breadcrumb.

SidebarThis page

Where you are in the app.

Room to focus

Toggle the live navigation.

The main sections of an app.

Tabs

Views of one thing.

Website refresh

Active

Design studio ยท Updated today

Tasks12
Members3
Due dateOct 24

Overview, activity, and settings.

Breadcrumb

The path back up.

Select a parent to go back.

Pages nested inside others.

Fig. 2 Three ways to move around. Pick by what people are moving between.

How it behaves

Wrap the layout in SidebarProvider. Compose SidebarHeader, SidebarContent, SidebarGroup, SidebarMenu, and SidebarFooter inside Sidebar.

The documentation navigation renders this registry source. Below 768px, Sidebar uses the installed Sheet for modal focus, Escape dismissal, and background interaction locking.

Use collapsible=icon, offcanvas (default), or none. Use SidebarInset as the content sibling when variant=inset; the provider and sidebar must share that layout.

SidebarTrigger and Cmd/Ctrl+B toggle the provider. open/onOpenChange support controlled desktop state; mobile state is independent. Desktop changes write sidebar_state; read it in your application and pass defaultOpen if you need restoration.

SidebarRail toggles on click and resizes on drag between 192px and 384px; dragging well past the minimum collapses the sidebar. Width lives in the provider as --sidebar-width. Drags write sidebar_width; read it and pass defaultWidth (pixels) if you need restoration. Keyboard users toggle with Cmd/Ctrl+B.

All upstream parts remain available, including submenus, actions, badges, skeletons, rail, and menu tooltips. Compose links with render={<a href=... />}. Place TooltipProvider around the application.

Desktop layout changes are immediate. The mobile Sheet retains its short pointer transition and reduced-motion alternative.

Build it

Add it with the shadcn CLI:

Terminal

A complete example. Change the values to fit your product:

sidebar-example.tsx

The full source is yours to edit once installed:

sidebar.tsx