Navigation
Sidebar
The side navigation for app layouts, with groups, badges, sub-items and an icon-only collapsed state. On screens under 768px it opens as a sheet.
import * as Sidebar from '@statix/ui/sidebar';Examples
App shell
Sidebar.Provider wraps the layout, Sidebar.Root holds the navigation and Sidebar.Inset the page. collapsible="icon" shrinks it to a 56px rail with tooltips.
<script lang="ts">
import * as Sidebar from '@statix/ui/sidebar';
import * as Breadcrumb from '@statix/ui/breadcrumb';
import FileTextIcon from '@lucide/svelte/icons/file-text';
import GlobeIcon from '@lucide/svelte/icons/globe';
import HouseIcon from '@lucide/svelte/icons/house';
import LayoutGridIcon from '@lucide/svelte/icons/layout-grid';
import LifeBuoyIcon from '@lucide/svelte/icons/life-buoy';
import MailIcon from '@lucide/svelte/icons/mail';
import SettingsIcon from '@lucide/svelte/icons/settings';
const products = [
{ title: 'Start', icon: HouseIcon },
{ title: 'Websites', icon: LayoutGridIcon, badge: '3' },
{ title: 'E-Mail', icon: MailIcon, badge: '5' },
{ title: 'Domains', icon: GlobeIcon },
{ title: 'Invoices', icon: FileTextIcon }
];
let active = $state('Websites');
</script>
<!--
In an app, drop the class props: the sidebar is fixed to the viewport by default.
Here it is pinned inside the preview box.
-->
<Sidebar.Provider class="relative h-[560px] min-h-0 overflow-hidden">
<Sidebar.Root collapsible="icon" class="absolute h-full">
<Sidebar.Header>
<Sidebar.Menu>
<Sidebar.MenuItem>
<Sidebar.MenuButton size="lg" class="hover:bg-transparent">
<span
class="flex size-8 shrink-0 items-center justify-center rounded-sm bg-ink text-label text-white"
>LB</span
>
<span class="flex flex-col leading-tight">
<span class="text-body font-medium text-ink">Laura Berger</span>
<span class="text-small text-muted-foreground">Customer 104 233</span>
</span>
</Sidebar.MenuButton>
</Sidebar.MenuItem>
</Sidebar.Menu>
</Sidebar.Header>
<Sidebar.Content>
<Sidebar.Group>
<Sidebar.GroupLabel>Your products</Sidebar.GroupLabel>
<Sidebar.GroupContent>
<Sidebar.Menu>
{#each products as item (item.title)}
<Sidebar.MenuItem>
<Sidebar.MenuButton
isActive={active === item.title}
tooltipContent={item.title}
onclick={() => (active = item.title)}
>
<item.icon />
<span>{item.title}</span>
</Sidebar.MenuButton>
{#if item.badge}
<Sidebar.MenuBadge>{item.badge}</Sidebar.MenuBadge>
{/if}
</Sidebar.MenuItem>
{/each}
</Sidebar.Menu>
</Sidebar.GroupContent>
</Sidebar.Group>
</Sidebar.Content>
<Sidebar.Footer>
<Sidebar.Menu>
<Sidebar.MenuItem>
<Sidebar.MenuButton tooltipContent="Settings">
<SettingsIcon />
<span>Settings</span>
</Sidebar.MenuButton>
</Sidebar.MenuItem>
<Sidebar.MenuItem>
<Sidebar.MenuButton tooltipContent="Support">
<LifeBuoyIcon />
<span>Support: 040 468 970 790</span>
</Sidebar.MenuButton>
</Sidebar.MenuItem>
</Sidebar.Menu>
</Sidebar.Footer>
<Sidebar.Rail />
</Sidebar.Root>
<Sidebar.Inset>
<header class="flex h-16 items-center gap-3 border-b border-border px-6">
<Sidebar.Trigger class="-ml-2" />
<Breadcrumb.Root>
<Breadcrumb.List>
<Breadcrumb.Item>
<Breadcrumb.Link href="#start">Customer area</Breadcrumb.Link>
</Breadcrumb.Item>
<Breadcrumb.Separator />
<Breadcrumb.Item>
<Breadcrumb.Page>{active}</Breadcrumb.Page>
</Breadcrumb.Item>
</Breadcrumb.List>
</Breadcrumb.Root>
</header>
<div class="p-6">
<h2 class="text-title text-ink">{active}</h2>
<p class="mt-2 text-body text-ink-2">
Press Ctrl+B or the button in the header to collapse the sidebar to icons.
</p>
</div>
</Sidebar.Inset>
</Sidebar.Provider>Menu with badges and sub-items
collapsible="none" renders a plain panel you can place anywhere. MenuSub nests a level, MenuBadge shows a count, GroupAction adds a button to the group.
<script lang="ts">
import * as Sidebar from '@statix/ui/sidebar';
import GlobeIcon from '@lucide/svelte/icons/globe';
import LayoutGridIcon from '@lucide/svelte/icons/layout-grid';
import MailIcon from '@lucide/svelte/icons/mail';
import PlusIcon from '@lucide/svelte/icons/plus';
const websites = ['yoga-berger.de', 'berger-physio.de', 'laufgruppe-altona.de'];
</script>
<Sidebar.Provider class="min-h-0 w-auto">
<Sidebar.Root collapsible="none" class="h-auto rounded-lg border border-border">
<Sidebar.Content>
<Sidebar.Group>
<Sidebar.GroupLabel>Websites</Sidebar.GroupLabel>
<Sidebar.GroupAction title="Add website">
<PlusIcon />
<span class="sr-only">Add website</span>
</Sidebar.GroupAction>
<Sidebar.GroupContent>
<Sidebar.Menu>
<Sidebar.MenuItem>
<Sidebar.MenuButton isActive>
<LayoutGridIcon />
<span>All websites</span>
</Sidebar.MenuButton>
<Sidebar.MenuBadge>3</Sidebar.MenuBadge>
<Sidebar.MenuSub>
{#each websites as site, i (site)}
<Sidebar.MenuSubItem>
<Sidebar.MenuSubButton href="#{site}" isActive={i === 0}>
<span>{site}</span>
</Sidebar.MenuSubButton>
</Sidebar.MenuSubItem>
{/each}
</Sidebar.MenuSub>
</Sidebar.MenuItem>
<Sidebar.MenuItem>
<Sidebar.MenuButton>
<MailIcon />
<span>E-Mail</span>
</Sidebar.MenuButton>
<Sidebar.MenuBadge>5</Sidebar.MenuBadge>
</Sidebar.MenuItem>
<Sidebar.MenuItem>
<Sidebar.MenuButton>
<GlobeIcon />
<span>Domains</span>
</Sidebar.MenuButton>
</Sidebar.MenuItem>
</Sidebar.Menu>
</Sidebar.GroupContent>
</Sidebar.Group>
</Sidebar.Content>
</Sidebar.Root>
</Sidebar.Provider>Guidelines
Do
- Keep top-level items to the product areas: Websites, E-Mail, Domains, Invoices.
- Mark the current page with isActive and set aria-current="page" on links.
- Pass tooltipContent so collapsed icons still have a name on hover.
Don't
- Do not use the sidebar on marketing pages. Use the nav bar.
- Do not nest deeper than one MenuSub level.
- Do not put primary actions in the sidebar. They belong on the page.
Accessibility
- Wrap Sidebar.Root in a <nav> or give the menu an aria-label when it is the main navigation.
- Ctrl+B (Cmd+B on macOS) toggles the sidebar. Sidebar.Trigger is labelled "Toggle Sidebar".
- On mobile the sidebar opens in a dialog sheet with a hidden title, so focus is trapped and Escape closes it.
- Menu buttons render <button> by default. Use the child snippet to render an <a> for navigation.
API reference
Sidebar.Provider
renders<div> and accepts its attributesHolds the open state and the keyboard shortcut. Wraps the sidebar and the page.
| Prop | Type | Default |
|---|---|---|
open bind | boolean Expanded or collapsed on desktop. | true |
onOpenChange | (open: boolean) => void Called when the state changes. The state is also stored in the sidebar_state cookie. | – |
class | ClassValue Merged with the wrapper classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="sidebar-wrapper" | Always present. |
Sidebar.Root
renders<div> and accepts its attributes| Prop | Type | Default |
|---|---|---|
side | 'left' | 'right' Which edge it sits on. | 'left' |
variant | 'sidebar' | 'floating' | 'inset' sidebar has a hairline edge, floating is a rounded card, inset puts the page in a card. | 'sidebar' |
collapsible | 'offcanvas' | 'icon' | 'none' offcanvas slides away, icon shrinks to a rail, none never collapses. | 'offcanvas' |
class | ClassValue Merged with the container classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="sidebar" | Always present. |
data-state | "expanded" or "collapsed". |
data-collapsible | The collapse mode while collapsed, else empty. |
data-variant / data-side | The current variant and side. |
Sidebar.MenuButton
renders<button> and accepts its attributes40px row with an 18px icon and 15px label. Active rows are primary-soft.
| Prop | Type | Default |
|---|---|---|
isActive | boolean Marks the current page. | false |
variant | 'default' | 'outline' outline adds a hairline ring. | 'default' |
size | 'sm' | 'default' | 'lg' 32, 40 or 48px. | 'default' |
tooltipContent | string | Snippet Tooltip shown when the sidebar is collapsed to icons. | – |
tooltipContentProps | Tooltip.Content props Passed to the tooltip. | – |
child | Snippet<[{ props }]> Render your own element, usually an <a>, and spread props on it. | – |
class | ClassValue Merged with the button classes. | – |
| Data attribute | Meaning |
|---|---|
data-slot="sidebar-menu-button" | Always present. |
data-active | "true" when isActive. |
data-size | The size. |
Sidebar.MenuSubButton
renders<a> and accepts its attributes| Prop | Type | Default |
|---|---|---|
href | string Link target. | – |
isActive | boolean Marks the current page. | false |
size | 'sm' | 'md' 32 or 36px. | 'md' |
child | Snippet<[{ props }]> Render your own element. | – |
| Data attribute | Meaning |
|---|---|
data-active | "true" when isActive. |
Sidebar.MenuAction
renders<button> and accepts its attributesA small round button at the end of a menu row.
| Prop | Type | Default |
|---|---|---|
showOnHover | boolean Hide until the row is hovered or focused (desktop). | false |
child | Snippet<[{ props }]> Render your own element, for example a dropdown trigger. | – |
Sidebar.GroupLabel / Sidebar.GroupAction
renders<div> / <button> and accepts its attributesA 13px label above a group and an optional round button next to it. Both accept child.
| Prop | Type | Default |
|---|---|---|
class | ClassValue Merged with the part classes. | – |
Sidebar.Trigger
renders<button> and accepts its attributesGhost icon button that toggles the sidebar.
| Prop | Type | Default |
|---|---|---|
onclick | (e: MouseEvent) => void Runs before the toggle. | – |
Layout parts
Sidebar.Header, Sidebar.Content (scrolls), Sidebar.Footer, Sidebar.Group, Sidebar.GroupContent, Sidebar.Menu, Sidebar.MenuItem, Sidebar.MenuSub, Sidebar.MenuSubItem, Sidebar.MenuBadge, Sidebar.MenuSkeleton (showIcon), Sidebar.Separator, Sidebar.Input, Sidebar.Rail and Sidebar.Inset (the page, a <main>). Each takes class and ref and has a matching data-slot="sidebar-…".
useSidebar()
Returns the sidebar state inside a Provider: open, openMobile, state ("expanded" | "collapsed"), isMobile, setOpen, setOpenMobile and toggle.