Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Sidebar for Vue

An app sidebar for Vue on Ark UI: grouped links and menus in a rail that collapses to icons or slides off screen, toggled by a button or Ctrl+B.

On this page9 sections
UI library: Ark UI

A sidebar holds an app's main navigation in a rail down the side of the page: groups of links, a workspace switcher at the top, the account menu at the bottom. It folds to a strip of icons or slides away, and the page takes back the room.

Reach for it when a product has more destinations than fit across a header. A site with a handful of top-level pages is better served by a Navigation Menu, and a phone app with four or five sections by Bottom Navigation.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Sidebar anatomy: header, content, group label, menu item, footer, trigger

Usage

<script setup lang="ts">
import { HomeIcon, InboxIcon, SettingsIcon } from "lucide-vue-next";
import type { ReactNode } from "react";
import {
  Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent,
  SidebarGroupLabel, SidebarInset, SidebarMenu, SidebarMenuButton,
  SidebarMenuItem, SidebarProvider, SidebarTrigger,
} from "@/components/ui/sidebar";
</script>

SidebarProvider holds the open state, so it wraps both the Sidebar and the page in SidebarInset, where the SidebarTrigger that toggles it usually sits.

const items = [
  { href: "/", icon: HomeIcon, title: "Home" },
  { href: "/inbox", icon: InboxIcon, title: "Inbox" },
  { href: "/settings", icon: SettingsIcon, title: "Settings" },
];

export const AppLayout = ({ children }: { children: ReactNode }) => (
  <SidebarProvider>
    <Sidebar collapsible="icon">
      <SidebarContent>
        <SidebarGroup>
          <SidebarGroupLabel>Application</SidebarGroupLabel>
          <SidebarGroupContent>
            <SidebarMenu>
              {items.map((item) => (
                <SidebarMenuItem key={item.title}>
                  <SidebarMenuButton asChild tooltip={item.title}>
                    <a href={item.href}>
                      <item.icon aria-hidden="true" />
                      <span>{item.title}</span>
                    </a>
                  </SidebarMenuButton>
                </SidebarMenuItem>
              ))}
            </SidebarMenu>
          </SidebarGroupContent>
        </SidebarGroup>
      </SidebarContent>
    </Sidebar>
    <SidebarInset>
      <header className="flex h-12 items-center px-2">
        <SidebarTrigger />
      </header>
      {children}
    </SidebarInset>
  </SidebarProvider>
);

Accessibility

Each row is a real link or button, so it sits in the tab order and Enter follows or presses it. SidebarTrigger is a button named Toggle Sidebar. Collapsed to icons, a row keeps its label as its accessible name, and the tooltip you give it shows that label beside the icon.

Two things are left to you. The sidebar renders no nav element, so put one with an aria-label around the groups of links. And isActive only changes how a row looks, so add aria-current="page" to the link for the page that is open.

Tab
Moves focus to the next link or button in the sidebar, and from the last one on into the page.
Shift+Tab
Moves focus to the previous link or button.
Enter
Follows the focused link, or presses the focused button, such as a row that opens its sub-items or a menu.
Space
Presses the focused button. Links don't respond to it.
Ctrl+B
Opens or closes the sidebar from anywhere on the page, a plain text field included, or ⌘ + B on a Mac. In a rich-text editor the keys still make text bold, because the sidebar leaves them to any element with contenteditable and to a handler that has already used them. Set shortcut to false on SidebarProvider to turn it off.

Demos

RTL

The full app shell in Arabic, with dir set to rtl on the frame around it and no direction prop on the sidebar. The rail sits on the right, where an Arabic line starts, floats with a gap around it and collapses to icons, and its menus open to the left, toward the page. Use it as the starting point for an Arabic or Hebrew interface.

Preview width

FAQ

Should I use a Sidebar or a Navigation Menu for my app?

Use a sidebar for an app people work inside, with destinations in several groups, a workspace or project switcher and an account menu that stay in reach on every screen. It takes a column of the layout and earns it by being there all the time.

A Navigation Menu suits a marketing site or docs with a few top-level sections across the header, each opening a panel of links. Many products use both, the menu on the public site and the sidebar once someone signs in.

How do I open or close the Sidebar from my own state in Vue?

Bind open on SidebarProvider and listen for its open-change event, which receives the next boolean. Set defaultOpen instead when you only need the first state.

Any part under the provider can also call useSidebar, which returns open, setOpen, toggleSidebar and state, either expanded or collapsed. It throws when called outside SidebarProvider, so keep the provider high enough in the layout to cover the header where your own buttons live.

How do I keep the Sidebar open or closed after a page reload?

The provider already writes the desktop state to a cookie named sidebar_state each time it changes, kept for seven days, but it never reads that cookie back. Read it where the page is rendered and pass the result to defaultOpen on SidebarProvider.

Read it on the server if you can, so the first paint already has the right width instead of jumping after hydration. Set persist to false when you would rather keep the state yourself, in local storage or a user setting.

How do I make the Sidebar collapse to icons instead of sliding away?

Set collapsible to icon on Sidebar. The default, offcanvas, slides the whole rail off the edge, icon leaves a 3rem strip with each row's icon showing, and none keeps it open with nothing to toggle.

In the icon strip, give each SidebarMenuButton a tooltip with its label, which shows only while the sidebar is collapsed. Hide a group that means nothing as icons with group-data-[collapsible=icon]:hidden, as the projects list in the demo above does.

How do I put the Sidebar on the right side of the page?

Set placement to right on Sidebar. It names the end of the layout rather than the screen's right edge, so on a right-to-left page the rail moves to the left. The border, the drag handle and the tooltips move with it.

The RTL demo shows the other case, where the page itself reads right to left and the default side already lands on the right.

What happens to the Sidebar on a phone?

In this port nothing replaces the rail yet. Its provider sets isMobile to false for good, so below 768px, where the rail is hidden, SidebarTrigger changes the desktop state and no sheet opens. Until that is fixed, show the same links in a Sheet of your own on narrow screens.

How do I highlight the current page's link in the Sidebar?

Compare each item's address with the router's current path and set isActive on the SidebarMenuButton or SidebarMenuSubButton that matches. It sets data-active, which the accent background keys on. Add aria-current="page" to the same link, since isActive tells a screen reader nothing.

To use your router's link component, render it through asChild on SidebarMenuButton.

How do I change the Sidebar's width or colors?

Set --sidebar-width and --sidebar-width-icon in the style of SidebarProvider. The provider applies 16rem and 3rem, and what you pass replaces them. Colors come from the sidebar tokens in your CSS, --sidebar, --sidebar-foreground, --sidebar-accent and --sidebar-border among them, so the rail can differ from the page without a class on every part.

Dragging SidebarRail also resizes an open sidebar between 160 and 360 pixels, and dragging it well past the narrow end collapses it. That width isn't saved, so it resets on the next load.

API Reference

PropType
collapsible?"offcanvas" | "icon" | "none"

Collapse behavior on desktop.

Type
"offcanvas" | "icon" | "none"
Default
"offcanvas"
placement?"left" | "right"

Which edge of the layout the sidebar sits on.

Type
"left" | "right"
Default
"left"
variant?"sidebar" | "floating" | "inset"

Visual treatment of the rail.

Type
"sidebar" | "floating" | "inset"
Default
"sidebar"

SidebarProvider

<div>

PropType
open?boolean

The open state of the sidebar. Two-way with v-model:open.

defaultOpen?boolean

The default open state of the sidebar.

Default
true
persist?boolean

Persist the desktop open state to a cookie.

Default
true
shortcut?boolean

Toggle the sidebar with ⌘B / Ctrl+B.

Default
true
class?string

Merged with the part's classes.

EventType
@open-change(open: boolean) → void

The function to call when the open state of the sidebar changes.

Parameters

open – boolean

Returns
void

SidebarTrigger

<span> data-slot="sidebar-trigger"

PropType
clickEffect?boolean

Apply a click effect to the button.

Default
true
isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

The size.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"md"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

The visual style.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"default"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"trigger"
Default
"trigger"

SidebarRail

<button> data-slot="sidebar-rail"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"rail"
Default
"rail"

SidebarInset

<main> data-slot="sidebar-inset"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

SidebarInput

data-slot="sidebar-input"

PropType
size?"lg" | "md" | "sm"

The size.

Type
"lg" | "md" | "sm"
Default
"md"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"input"
Default
"input"

SidebarHeader

<div> data-slot="sidebar-header"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"header"
Default
"header"

SidebarFooter

<div> data-slot="sidebar-footer"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"footer"
Default
"footer"

SidebarSeparator

data-slot="sidebar-separator"

PropType
orientation?"horizontal" | "vertical"

The orientation of the separator.

Type
"horizontal" | "vertical"
Default
"horizontal"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"separator"
Default
"separator"

SidebarContent

<div> data-slot="sidebar-content"

PropType
scrollFade?boolean

Whether to add a scroll fade effect to the sidebar content.

Default
false
class?string

Merged with the part's classes.

AttributeType
data-sidebar"content"
Default
"content"

SidebarGroup

<div>

PropType
open?boolean

Controlled open state when collapsible is true. Two-way with v-model:open.

defaultOpen?boolean

Uncontrolled initial open state when collapsible is true.

Default
true
collapsible?boolean

Makes the group's label a toggle that collapses SidebarGroupContent.

Default
false
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

EventType
@open-change(details: OpenChangeDetails) → void

Called when a collapsible group opens or closes.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void

SidebarGroupLabel

<div> data-slot="sidebar-group-label"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"group-label"
Default
"group-label"

SidebarGroupAction

<button> data-slot="sidebar-group-action"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"group-action"
Default
"group-action"

SidebarGroupContent

<div> data-slot="sidebar-group-content"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"group-content"
Default
"group-content"

SidebarMenu

<ul> data-slot="sidebar-menu"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu"
Default
"menu"

SidebarMenuItem

<li> data-slot="sidebar-menu-item"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-item"
Default
"menu-item"

SidebarMenuButton

<button> data-slot="sidebar-menu-button"

PropType
isActive?boolean

Whether the button is active.

Default
false
size?SidebarMenuButtonSize

Visual size of the row. default matches md.

Default
"md"
tooltip?string | React.ComponentProps<typeof TooltipContent>

The tooltip to display when hovering over the button.

Type
string | React.ComponentProps<typeof TooltipContent>
variant?"default" | "ghost" | "outline"

The visual style.

Type
"default" | "ghost" | "outline"
Default
"default"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-active?string

Mirrors isActive.

data-sidebar"menu-button"
Default
"menu-button"
data-size?string

Mirrors menuSize.

SidebarMenuAction

<button> data-slot="sidebar-menu-action"

PropType
showOnHover?boolean

Hides the action until its menu item is hovered or focused, or its menu is open. Always shown below md.

Default
false
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-action"
Default
"menu-action"

SidebarMenuBadge

<div> data-slot="sidebar-menu-badge"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-badge"
Default
"menu-badge"

SidebarMenuSkeleton

<div> data-slot="sidebar-menu-skeleton"

PropType
showIcon?boolean

Draws an icon placeholder before the text line.

Default
false
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-skeleton"
Default
"menu-skeleton"
CSS variableType
--skeleton-widthstring

SidebarMenuSub

<ul> data-slot="sidebar-menu-sub"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-sub"
Default
"menu-sub"

SidebarMenuSubItem

<li> data-slot="sidebar-menu-sub-item"

PropType
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-sidebar"menu-sub-item"
Default
"menu-sub-item"

SidebarMenuSubButton

<a> data-slot="sidebar-menu-sub-button"

PropType
isActive?boolean

Whether the link is the current page: highlighted, and data-active.

Default
false
size?"sm" | "md"

The size.

Type
"sm" | "md"
Default
"md"
asChild?boolean

Use the provided child element as the default rendered element, combining their props and behavior.

class?string

Merged with the part's classes.

AttributeType
data-active?string

Mirrors isActive.

data-sidebar"menu-sub-button"
Default
"menu-sub-button"
data-size?string

Mirrors size.

useSidebar