Skip to content
TrademarkTrademark
Docs
Components

Sidebar

Updated: November 13, 2026
View on GitHub

A Sidebar is the frame around a Nav: it owns the width, the collapse, the resize handle and the phone drawer, so the Nav inside only has to say what the rows are. Drag its edge to resize it. Drag past the minimum and it folds into an icon rail; drag the rail out and it opens again. Double-click the edge to reset it. ⌘B (Ctrl+B elsewhere) folds it from anywhere outside a text field.

Composition

  • Sidebar is the frame: an aside that holds the width and draws the handle on its edge.
  • SidebarHeader and SidebarFooter stay put. Put the workspace switcher on top and the account at the bottom. In the rail they clip to their leading mark rather than wrap.
  • SidebarContent takes the space left and scrolls on its own. It holds the Nav.
  • SidebarTrigger folds and unfolds it, or opens the drawer on a phone. Its tooltip names the shortcut. Put it in the top bar or in the SidebarHeader.
  • SidebarProvider holds the state for the Sidebar and for anything outside it that reads or changes it: the trigger in the top bar, ⌘B, useSidebar(). A Sidebar with no provider around it makes its own.

Remembering it

Give the provider a persist key and it keeps the width and the collapse in a cookie. Read the cookie on the server and pass it back as the defaults, and the first paint is already right: no default width that jumps once the browser has looked.

Both helpers are plain functions, safe to call in a server component and outside Next.js: read the cookie however your framework does and pass its value to parseSidebarCookie.

Peeking from the rail

With expandOnHover, a mouse resting on the rail opens it over the page, labels and all, and the page beside it does not move. Keyboard focus opens it too; Escape or leaving closes it. Touch never opens it.

In the rail, a NavGroup is its icon, and a click opens its rows in a menu beside it.

Off canvas

collapsible="offcanvas" slides it out entirely instead of leaving a rail, for a chat list or a file tree that has no icons to keep. While it is out, nothing in it can be reached by Tab. collapsible={false} keeps it open.

Phones

Below mobileBelow (default s) the sidebar is a drawer from the left, with the same children at full labels. The SidebarTrigger opens it, and following a link inside closes it. mobileBelow={false} keeps the desktop sidebar at every width.

Keyboard

The edge is a focusable separator with its width as its value.

Key
Does
← / →Narrower or wider by 8px; 32px with Shift. Past the minimum, ← folds it.
Home / EndThe minimum or the maximum width.
EnterFolds or unfolds it.
⌘B / Ctrl+BFolds or unfolds it from anywhere outside a text field (shortcut).

Motion

The width eases between open, rail and hidden on the macro transition, and the Nav's labels fade on the micro one. Nothing animates while you drag, and with prefers-reduced-motion nothing animates at all.

API reference

Type
Default
collapsible
"rail" folds it to its icons, "offcanvas" slides it out, false keeps it open.
falserailoffcanvas
—
resizable
Draw the handle on its edge.
boolean—
expandOnHover
As a rail, open over the page on a resting mouse or keyboard focus.
boolean—
railWidth
The rail's width in pixels. Left out, 52 for a compact Nav and 80 for a normal one.
number—
labels
The handle's and the drawer's words, for another language.
{ resize?: string; menu?: string }—
defaultWidth
number—
width
number—
onWidthChange
(width: number) => void—
defaultCollapsed
boolean—
collapsed
boolean—
onCollapsedChange
(collapsed: boolean) => void—
minWidth
number—
maxWidth
number—
persist
string—
shortcut
stringfalse
—
mobileBelow
xssmlfalse
—
…and every FlexProps propinherited—
Type
Default
children
React.ReactNode—
defaultWidth
The open width to start from, in pixels, such as a saved one.
number256
width
The open width, when the host owns it.
number—
onWidthChange
Called once a resize ends.
(width: number) => void—
defaultCollapsed
Start folded.
booleanfalse
collapsed
Folded, when the host owns it.
boolean—
onCollapsedChange
Called with the state it moves to.
(collapsed: boolean) => void—
minWidth
The narrowest a drag can make it.
number200
maxWidth
The widest a drag can make it.
number400
persist
Keep width and collapse in a cookie under this key.
string—
shortcut
The key that folds it. false for none.
stringfalse
mod+b
mobileBelow
Below this breakpoint it is a drawer. false never.
xssmlfalse
s
Edit this page on GitHub