Introducing PrimeReact v11-alpha 🎉Discover Now

Sidebar

An unstyled layout component for building application navigation with collapsible panels, multi-variant styling, and composable menu structures.

Build fully custom application sidebars with compound components for layout, menus, and collapsible sections.

Navigation
  • 12
  • 3
Projects
Billing
Dashboard

Welcome back, John

Select an item from the sidebar to get started.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use Sidebar with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Layout, Root, Spacer, Panel, Body, Header, Content, Footer, Group, GroupLabel, GroupContent, Menu, MenuItem, MenuButton, MenuAction, MenuBadge, MenuSub, MenuSubItem, MenuSubButton, Trigger, Rail, Inset, Backdrop
  • Three visual variants: sidebar, floating, inset
  • Three collapsible modes: icon, offcanvas, none
  • Left and right side positioning
  • Multi-sidebar support with Layout + id/target
  • Collapsible menu items with animated expand/collapse via useMotion
  • Hover-to-open with configurable delays
  • Overlay mode with animated Backdrop
  • Controlled and uncontrolled open state

Usage#

import { Sidebar } from 'primereact/sidebar';
<Sidebar.Layout>
    <Sidebar.Root id="main" collapsible="icon">
        <Sidebar.Spacer />
        <Sidebar.Panel>
            <Sidebar.Body>
                <Sidebar.Header>...</Sidebar.Header>
                <Sidebar.Content>
                    <Sidebar.Group>
                        <Sidebar.GroupLabel>Navigation</Sidebar.GroupLabel>
                        <Sidebar.GroupContent>
                            <Sidebar.Menu>
                                <Sidebar.MenuItem>
                                    <Sidebar.MenuButton isActive>
                                        <HomeIcon />
                                        <span>Home</span>
                                    </Sidebar.MenuButton>
                                </Sidebar.MenuItem>
                            </Sidebar.Menu>
                        </Sidebar.GroupContent>
                    </Sidebar.Group>
                </Sidebar.Content>
                <Sidebar.Footer>...</Sidebar.Footer>
                <Sidebar.Rail />
            </Sidebar.Body>
        </Sidebar.Panel>
    </Sidebar.Root>
    <Sidebar.Inset>
        <Sidebar.Trigger />
        <main>Content</main>
    </Sidebar.Inset>
</Sidebar.Layout>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Sidebar.Trigger as="div">...</Sidebar.Trigger>

Render Function Children#

Sub-components accept a render function as children, providing access to the component instance.

<Sidebar.Content>{(instance) => <div>{instance.sidebar?.state.open ? 'Open' : 'Closed'}</div>}</Sidebar.Content>

Collapsible Menu Items#

Add collapsible prop to MenuItem for animated expandable submenus.

<Sidebar.MenuItem collapsible defaultOpen={false}>
    <Sidebar.MenuButton>
        <FolderIcon />
        <span>Documents</span>
    </Sidebar.MenuButton>
    <Sidebar.MenuSub>
        <Sidebar.MenuSubItem>
            <Sidebar.MenuSubButton>Shared</Sidebar.MenuSubButton>
        </Sidebar.MenuSubItem>
    </Sidebar.MenuSub>
</Sidebar.MenuItem>

Multi-Sidebar#

Use Layout with id and target props for multiple independent sidebars.

<Sidebar.Layout>
    <Sidebar.Root side="left" id="nav">
        ...
    </Sidebar.Root>
    <Sidebar.Inset>
        <Sidebar.Trigger target="nav" />
        <Sidebar.Trigger target="tools" />
    </Sidebar.Inset>
    <Sidebar.Root side="right" id="tools">
        ...
    </Sidebar.Root>
</Sidebar.Layout>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

SidebarLayout#

SidebarRoot#

AttributeValue
data-state"expanded" | "collapsed"
data-variant"sidebar" | "floating" | "inset"
data-collapsible"offcanvas" | "icon" | "" (empty when expanded)
data-collapsible-mode"offcanvas" | "icon" | "none" (always present)
data-side"left" | "right"
data-overlayPresent when overlay is true

SidebarSpacer#

SidebarPanel#

SidebarBody#

SidebarHeader#

SidebarContent#

SidebarFooter#

SidebarGroup#

SidebarGroupLabel#

SidebarGroupContent#

SidebarMenu#

SidebarMenuItem#

AttributeValue
data-openPresent when the menu item is expanded

SidebarMenuButton#

AttributeValue
data-active"true" when the button is active

SidebarMenuAction#

SidebarMenuBadge#

SidebarMenuSub#

SidebarMenuSubItem#

SidebarMenuSubButton#

AttributeValue
data-active"true" when the button is active
data-size"sm" when small size is set

SidebarTrigger#

SidebarRail#

SidebarInset#

SidebarBackdrop#

Uses the Backdrop component internally for animated overlay rendering.

Accessibility#

Screen Reader#

Sidebar uses navigation landmark role by default. The Trigger element toggles the sidebar open state. Each MenuItem uses button role for interactive menu items.

Keyboard Support#

KeyFunction
tabMoves focus to the next focusable element.
shift + tabMoves focus to the previous focusable element.
enterActivates the focused menu button or trigger.
spaceActivates the focused menu button or trigger.