Sidebar
A composable, themeable and customizable sidebar component.
Sidebars are one of the most complex components to build. They are central to any application and often contain a lot of moving parts.
We now have a solid foundation to build on top of. Composable. Themeable. Customizable.
Installation
Usage
@inherits LayoutComponentBase
<SidebarProvider>
<AppSidebar />
<main>
<SidebarTrigger />
@Body
</main>
</SidebarProvider><Sidebar>
<SidebarHeader />
<SidebarContent>
<SidebarGroup />
<SidebarGroup />
</SidebarContent>
<SidebarFooter />
</Sidebar>Composition
Use the following composition to build a Sidebar layout:
SidebarProvider
├── Sidebar
│ ├── SidebarHeader
│ ├── SidebarContent
│ │ ├── SidebarGroup
│ │ │ ├── SidebarGroupLabel
│ │ │ ├── SidebarGroupAction
│ │ │ ├── SidebarGroupContent
│ │ │ └── SidebarMenu
│ │ │ ├── SidebarMenuItem
│ │ │ │ ├── SidebarMenuButton
│ │ │ │ ├── SidebarMenuAction
│ │ │ │ └── SidebarMenuBadge
│ │ │ └── SidebarMenuItem
│ │ │ ├── SidebarMenuButton
│ │ │ └── SidebarMenuSub
│ │ │ ├── SidebarMenuSubItem
│ │ │ └── SidebarMenuSubItem
│ │ └── SidebarGroup
│ │ └── SidebarMenu
│ │ ├── SidebarMenuItem
│ │ └── SidebarMenuItem
│ ├── SidebarFooter
│ └── SidebarRail
├── SidebarInset
└── SidebarTriggerStructure
- SidebarProvider — Handles collapsible state and provides sidebar context to child components.
- Sidebar — The main collapsible sidebar panel.
- SidebarHeader — Sticky at the top; use for branding, titles, or workspace switchers.
- SidebarFooter — Sticky at the bottom; use for user menus, settings, or actions.
- SidebarContent — Scrollable region between the header and footer.
- SidebarGroup — Groups related navigation with optional label, action, and content areas.
- SidebarMenu / SidebarMenuItem — Menu structure for links, badges, actions, and nested submenus.
- SidebarRail — A strip along the sidebar's edge that toggles it.
- SidebarInset — Wraps main content when using the
Insetvariant. - SidebarTrigger — Control that toggles the sidebar open or collapsed.
SidebarProvider
The SidebarProvider component is used to provide the sidebar context to the Sidebar component. You should always wrap your application in a SidebarProvider component.
Parameters
Width
If you have a single sidebar in your application, you can use the Width and WidthMobile constants in SidebarProvider.razor to set the width of the sidebar.
private const string Width = "16rem";
public const string WidthMobile = "18rem";For multiple sidebars in your application, you can set the --sidebar-width CSS variable with the Style parameter.
<SidebarProvider Style="--sidebar-width: 20rem">
<Sidebar />
</SidebarProvider>Keyboard Shortcut
To trigger the sidebar, you use the cmd+b keyboard shortcut on Mac and ctrl+b on Windows.
private const string KeyboardShortcut = "b";Persisted State
The provider keeps the sidebar's state in the sidebar_state cookie. Read it when the page renders and pass it as DefaultOpen to start the way the user left it.
@inject IHttpContextAccessor HttpContextAccessor
<SidebarProvider DefaultOpen="@DefaultOpen">
<AppSidebar />
<main>@Body</main>
</SidebarProvider>
@code {
private bool DefaultOpen =>
HttpContextAccessor.HttpContext?.Request.Cookies[SidebarProvider.CookieName] != "false";
}Sidebar
The main Sidebar component used to render a collapsible sidebar.
Parameters
Inset variant, remember to wrap your main content in a SidebarInset component.<SidebarProvider>
<Sidebar Variant="SidebarVariant.Inset" />
<SidebarInset>
<main>@Body</main>
</SidebarInset>
</SidebarProvider>SidebarContext
The SidebarProvider cascades a SidebarContext. Take it as a cascading parameter to read or control the sidebar from any component inside the provider.
<p>The sidebar is @Sidebar.State.ToString().ToLowerInvariant().</p>
@code {
[CascadingParameter] private SidebarContext Sidebar { get; set; } = null!;
}SidebarHeader
Use the SidebarHeader component to add a sticky header to the sidebar.
<Sidebar>
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger>
<Render Context="trigger">
<SidebarMenuButton @attributes="trigger.Attributes">
Select Workspace
<Icon Data="LucideIcons.ChevronDown" class="ml-auto" />
</SidebarMenuButton>
</Render>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<span>Blazix Inc</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
</Sidebar>SidebarFooter
Use the SidebarFooter component to add a sticky footer to the sidebar.
<Sidebar>
<SidebarFooter>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton>
<Icon Data="LucideIcons.UserRound" /> Username
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
</Sidebar>SidebarContent
The SidebarContent component is used to wrap the content of the sidebar. This is where you add your SidebarGroup components. It is scrollable.
<Sidebar>
<SidebarContent>
<SidebarGroup />
<SidebarGroup />
</SidebarContent>
</Sidebar>SidebarGroup
Use the SidebarGroup component to create a section within the sidebar.
A SidebarGroup has a SidebarGroupLabel, a SidebarGroupContent and an optional SidebarGroupAction.
<SidebarGroup>
<SidebarGroupLabel>Application</SidebarGroupLabel>
<SidebarGroupAction>
<Icon Data="LucideIcons.Plus" /> <span class="sr-only">Add Project</span>
</SidebarGroupAction>
<SidebarGroupContent></SidebarGroupContent>
</SidebarGroup>To make a SidebarGroup collapsible, wrap it in a Collapsible.
<Collapsible Open="true" Class="group/collapsible">
<SidebarGroup>
<SidebarGroupLabel>
<Render Context="label">
<CollapsibleTrigger @attributes="label.Attributes">
Help
<Icon Data="LucideIcons.ChevronDown" class="ml-auto transition-transform group-data-open/collapsible:rotate-180" />
</CollapsibleTrigger>
</Render>
</SidebarGroupLabel>
<CollapsibleContent>
<SidebarGroupContent />
</CollapsibleContent>
</SidebarGroup>
</Collapsible>SidebarMenu
The SidebarMenu component is used for building a menu within a SidebarGroup.
<SidebarMenu>
@foreach (var project in Projects)
{
<SidebarMenuItem @key="project.Name">
<SidebarMenuButton>
<Render Context="link">
<a @attributes="link.Attributes" href="@project.Url">
<Icon Data="@project.Icon" />
<span>@project.Name</span>
</a>
</Render>
</SidebarMenuButton>
</SidebarMenuItem>
}
</SidebarMenu>SidebarMenuButton
The SidebarMenuButton component is used to render a menu button within a SidebarMenuItem.
By default, the SidebarMenuButton renders a button but you can use the Render parameter to render a different element, such as an <a> tag or a NavLink.
Use the IsActive parameter to mark a menu item as active.
<SidebarMenuButton IsActive="true">
<Render Context="link">
<a @attributes="link.Attributes" href="#">Home</a>
</Render>
</SidebarMenuButton>SidebarMenuAction
The SidebarMenuAction component is used to render a menu action within a SidebarMenuItem.
<SidebarMenuItem>
<SidebarMenuButton>
<Render Context="link">
<a @attributes="link.Attributes" href="#">
<Icon Data="LucideIcons.House" />
<span>Home</span>
</a>
</Render>
</SidebarMenuButton>
<SidebarMenuAction>
<Icon Data="LucideIcons.Plus" /> <span class="sr-only">Add Project</span>
</SidebarMenuAction>
</SidebarMenuItem>SidebarMenuSub
The SidebarMenuSub component is used to render a submenu within a SidebarMenu.
<SidebarMenuItem>
<SidebarMenuButton />
<SidebarMenuSub>
<SidebarMenuSubItem>
<SidebarMenuSubButton />
</SidebarMenuSubItem>
</SidebarMenuSub>
</SidebarMenuItem>SidebarMenuBadge
The SidebarMenuBadge component is used to render a badge within a SidebarMenuItem.
<SidebarMenuItem>
<SidebarMenuButton />
<SidebarMenuBadge>24</SidebarMenuBadge>
</SidebarMenuItem>SidebarMenuSkeleton
The SidebarMenuSkeleton component is used to render a skeleton for a SidebarMenu.
<SidebarMenu>
@for (var i = 0; i < 5; i++)
{
<SidebarMenuItem>
<SidebarMenuSkeleton />
</SidebarMenuItem>
}
</SidebarMenu>SidebarTrigger
Use the SidebarTrigger component to render a button that toggles the sidebar.
To build your own trigger, take the SidebarContext and call ToggleAsync.
<button type="button" @onclick="Sidebar.ToggleAsync">Toggle Sidebar</button>
@code {
[CascadingParameter] private SidebarContext Sidebar { get; set; } = null!;
}SidebarRail
The SidebarRail component is used to render a rail within a Sidebar. This rail can be used to toggle the sidebar.
<Sidebar>
<SidebarHeader />
<SidebarContent>
<SidebarGroup />
</SidebarContent>
<SidebarFooter />
<SidebarRail />
</Sidebar>Controlled Sidebar
Use @bind-Open on the SidebarProvider to control the sidebar.
<SidebarProvider @bind-Open="_open">
<Sidebar />
</SidebarProvider>
@code {
private bool? _open = false;
}Theming
We use the following CSS variables to theme the sidebar. They are in Styles/theme.css.
:root {
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.205 0 0);
}
.dark {
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.922 0 0);
}Styling
Here are some tips for styling the sidebar based on different states.
<Sidebar Collapsible="SidebarCollapsible.Icon">
<SidebarContent>
<SidebarGroup Class="group-data-[collapsible=icon]:hidden" />
</SidebarContent>
</Sidebar><SidebarMenuItem>
<SidebarMenuButton />
<SidebarMenuAction Class="peer-data-[active=true]/menu-button:opacity-100" />
</SidebarMenuItem>RTL
To enable RTL support in Blazix, see the RTL configuration guide.
Translated with AI for the demo, so it may have mistakes.
API Reference
Sidebar
Other attributes are passed to the element it renders.
SidebarContent
Other attributes are passed to the element it renders.
SidebarFooter
Other attributes are passed to the element it renders.
SidebarGroup
Other attributes are passed to the element it renders.
SidebarGroupAction
Other attributes are passed to the element it renders.
SidebarGroupContent
Other attributes are passed to the element it renders.
SidebarGroupLabel
Other attributes are passed to the element it renders.
SidebarHeader
Other attributes are passed to the element it renders.
SidebarInput
Other attributes are passed to the element it renders.
SidebarInset
Other attributes are passed to the element it renders.
SidebarMenu
Other attributes are passed to the element it renders.
SidebarMenuAction
Other attributes are passed to the element it renders.
SidebarMenuBadge
Other attributes are passed to the element it renders.
SidebarMenuButton
Other attributes are passed to the element it renders.
SidebarMenuItem
Other attributes are passed to the element it renders.
SidebarMenuSkeleton
Other attributes are passed to the element it renders.
SidebarMenuSub
Other attributes are passed to the element it renders.
SidebarMenuSubButton
Other attributes are passed to the element it renders.
SidebarMenuSubItem
Other attributes are passed to the element it renders.
SidebarProvider
Other attributes are passed to the element it renders.
SidebarRail
Other attributes are passed to the element it renders.
SidebarSeparator
Other attributes are passed to the element it renders.
SidebarTrigger
Other attributes are passed to the element it renders.
Changelog
2026-11-24 Sidebar state and direction
SidebarContext.State is now a SidebarState: SidebarState.Expanded or
SidebarState.Collapsed, not the strings "expanded" or "collapsed". The
data-state attribute still says expanded or collapsed, so the styles don't change.
Sidebar's Dir is now a TextDirection: Dir="TextDirection.Rtl" instead of
Dir="rtl".
@if (Sidebar.State == SidebarState.Collapsed)
{
<p>The sidebar is collapsed.</p>
}
To get the new version, run dnx Blazix.Cli diff sidebar to see your changes, then
dnx Blazix.Cli add sidebar --overwrite.