Skip to content

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.

Updated 3 December 2026Tested with
  • 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

  1. Step 1: Missing SidebarProvider around both Sidebar and main

    SidebarTrigger and useSidebar() 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>  );}
  2. 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 inline mappings. Re-check shadcn/ui not working with Tailwind v4.

  3. 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. Add min-w-0 to <SidebarInset className="min-w-0"> and wrap tables in overflow-x-auto.

  4. Step 4: Sidebar doesn't collapse to icons

    Pass collapsible="icon" on <Sidebar collapsible="icon">. The default collapsible="offcanvas" slides the entire sidebar out of view instead of shrinking to an icon rail.

  5. Step 5: Mobile sheet flashes or ignores initial state in Next.js

    Read the sidebar_state cookie on the server in your Next.js layout and pass defaultOpen={defaultOpen} to SidebarProvider so 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).

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.