shadcn/ui Sidebar not working: layout, collapse and mobile fixes
Fix shadcn/ui Sidebar issues: missing SidebarProvider, Tailwind v4 --sidebar tokens, SidebarInset overflow, collapsible="icon", and SSR cookie state.
- shadcn 4.23.0
- Tailwind CSS 4.3.5
- Vite 8
- React 19.3
The shadcn/ui Sidebar is more than a styled <aside>: it relies on SidebarProvider context, CSS custom properties (--sidebar-width, --sidebar), and a mobile Sheet. When the sidebar refuses to collapse, overflows horizontally, or renders unstyled on Tailwind CSS v4, one of five setup pieces is missing.
Five causes and fixes
Step 1: Missing SidebarProvider around both Sidebar and main
SidebarTriggeranduseSidebar()throw or do nothing if they are not inside the same<SidebarProvider>as<Sidebar>. Wrap the whole dashboard layout:app/dashboard/layout.tsxTSX import { SidebarProvider, SidebarTrigger, SidebarInset } from "@/components/ui/sidebar";import { AppSidebar } from "@/components/app-sidebar"; export default function DashboardLayout({ children }: { children: React.ReactNode }) { return ( <SidebarProvider> <AppSidebar /> <SidebarInset> <header className="flex h-14 items-center gap-2 border-b px-4"> <SidebarTrigger /> </header> <main className="flex-1 p-6">{children}</main> </SidebarInset> </SidebarProvider> );}Step 2: Missing --sidebar-* tokens in global CSS (Tailwind v4)
If the sidebar background is transparent or has no border, your CSS is missing the sidebar colour tokens (
--sidebar,--sidebar-foreground,--sidebar-accent,--sidebar-border) or their@theme inlinemappings. Re-check shadcn/ui not working with Tailwind v4.Step 3: Horizontal overflow in SidebarInset
A wide table or code block inside
<main>pushes the flex layout off-screen unless the content column can shrink. Addmin-w-0to<SidebarInset className="min-w-0">and wrap tables inoverflow-x-auto.Step 4: Sidebar doesn't collapse to icons
Pass
collapsible="icon"on<Sidebar collapsible="icon">. The defaultcollapsible="offcanvas"slides the entire sidebar out of view instead of shrinking to an icon rail.Step 5: Mobile sheet flashes or ignores initial state in Next.js
Read the
sidebar_statecookie on the server in your Next.js layout and passdefaultOpen={defaultOpen}toSidebarProviderso SSR matches the client without layout shift.
Questions
Where can I see ready-made shadcn/ui dashboard layouts?
Browse our shadcn dashboard screens — complete app shells with sidebars, headers, tables and charts in light and dark mode.
Why does the Cmd+B keyboard shortcut not toggle my sidebar?
SidebarProvider registers the Cmd+B / Ctrl+B listener inside a useEffect. Make sure the component rendering SidebarProvider is a Client Component (or imports it from a "use client" file).
Related articles
- shadcn/uishadcn/ui not working with Tailwind v4: six causes and fixesUnstyled or transparent shadcn components on Tailwind v4 come from v3 leftovers: the old PostCSS plugin, @tailwind directives, hsl() wrappers, missing imports.
- shadcn/uishadcn/ui dark mode not working? Check these seven thingsIs the dark class on <html>? If not: no provider, a flash on load, or Astro view transitions. If it is: colours without a dark value or @theme without inline.
- shadcn/uishadcn/ui Combobox not scrolling inside a DialogFix a shadcn/ui Combobox or Popover inside a Dialog: set modal={true} on Popover, stop wheel propagation on CommandList, and fix focus trapping.
Still stuck? We answer every message ourselves. Write to us