Skip to main content
twblazor
Home
  • Get started
  • Tailwind with Blazor
  • Why twblazor?
  • Theme
  • Class Merge
    • Configuring localization
    • RTL Provider
  • Breadcrumb
  • Card
  • Carousel
  • Collapse
  • Context Menu
  • Drawer
  • Footer
  • Menu
  • Navbar
  • On This Page
  • Separator
  • Sidebar
  • Stepper
  • Tabs
  • Tree List
  • Container
  • Flex
  • Grid
  • Text
  • Link
  • Button
  • Form
    • AutocompleteNew
    • Checkbox
    • Color Picker
    • Date Picker
    • Date Range Picker
    • Datetime Picker
    • Datetime Range Picker
    • File Upload
    • Input GroupNew
    • NumericNew
    • Masked InputNew
    • Radio Button
    • Range SliderNew
    • RatingNew
    • Select
    • Slider
    • Switch
    • Tag InputNew
    • Text EditorNew
    • Textfield
    • Time Picker
    • Time Range Picker
  • Toggle
  • Toggle Group
  • Alert
  • Avatar
  • Badge
  • Chip
  • Empty
  • Icon
  • Popover
  • Progress
  • Skeleton
  • Spinner
  • Tooltip
  • Data Table
  • SpreadsheetNew
  • Column Filter Editor
  • Pagination
  • Pick List
  • Barcode
  • QR Code
  • Calendar
  • Table
  • Attachment
  • Overview
    • Bar
    • Bullet
    • Column
    • Dot Plot
    • Dumbbell
    • Icon
    • Lollipop
    • Radial Bar
    • Range
    • Word Cloud
    • Area
    • Bump
    • Bump Area
    • Candlestick
    • Gantt
    • Horizon
    • Line
    • Slope
    • Small Multiples
    • Stream Graph
    • Funnel
    • Gauge
    • Marimekko
    • Nightingale
    • Pie
    • Treemap
    • Waffle
    • Waterfall
    • Circular Treemap
    • Convex Treemap
    • Dendrogram
    • Sunburst
    • Barcode
    • Beeswarm
    • Box Plot
    • Density Plot
    • Histogram
    • Radial Histogram
    • Ridgeline
    • Strip Plot
    • Violin Plot
    • Categorical Scatter
    • Contour
    • Hexagonal Binning
    • Quadrant
    • Scatter
    • Heatmap
    • Matrix
    • Parallel Coordinates
    • Radar
    • Arc Diagram
    • Chord Diagram
    • Flowchart
    • Network Diagram
    • Sankey
    • Euler Diagram
    • Venn Diagram
  • Bubble
  • Marker
  • Message
  • Dialog Service
  • Toast Service
API DocumentationAI Agents & Skills
Home Get Started

Layout

TwSidebar

TwSidebar is a Blazor sidebar for navigation. Build it from SidebarContent markup or data-driven NavigationItems, with IsSearchable and a collapsible layout.

Last updated 7 November 2026

Basic sidebar

TwSidebar has all the functionality you'd want in a single component for a sidebar. You can customise the sidebar using both tailwind classes and additional twblazor Theme styling.
RAZOR
<TwSidebar IsSidebarOpen="true" Style="background-color: #ffffff;">
    <NavbarContent>
        <div class="items-center gap-1 ml-2">
            <a href="#" class="px-3 py-1.5 rounded-md text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors duration-150">Home</a>
            <a href="#" class="px-3 py-1.5 rounded-md text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors duration-150">About</a>
            <a href="#" class="px-3 py-1.5 rounded-md text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors duration-150">Services</a>
        </div>
    </NavbarContent>
    <HeaderContent>
        <a href="/sidebar/preview" class="flex items-center gap-2 px-4 py-3 border-b border-gray-200">
            <img src="_content/TwBlazor.Docs/images/logo.svg" alt="twblazor Logo" class="h-8 w-8 shrink-0" />
            <span class="text-xl font-bold tracking-tight text-gray-900">twblazor</span>
        </a>
    </HeaderContent>
    <SidebarContent>
        <a href="/sidebar/preview" class="flex items-center gap-2 mx-2 px-3 py-2 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-100 hover:text-gray-900 transition-colors duration-150">
            <span class="h-1.5 w-1.5 rounded-full bg-gray-400"></span>
            Sidebar Link
        </a>
        <a href="/sidebar/preview" class="flex items-center gap-2 mx-2 px-3 py-2 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-100 hover:text-gray-900 transition-colors duration-150">
            <span class="h-1.5 w-1.5 rounded-full bg-gray-400"></span>
            Sidebar Link
        </a>
        <a href="/sidebar/preview" class="flex items-center gap-2 mx-2 px-3 py-2 rounded-lg text-sm font-medium text-gray-700 hover:bg-gray-100 hover:text-gray-900 transition-colors duration-150">
            <span class="h-1.5 w-1.5 rounded-full bg-gray-400"></span>
            Sidebar Link
        </a>
    </SidebarContent>
    <ChildContent>
        <div class="p-6 max-w-2xl">
            <h2 class="text-lg font-semibold text-gray-900 mb-2">Main Content</h2>
            <p class="text-sm text-gray-600 leading-relaxed">
                Use <code class="px-1.5 py-0.5 rounded bg-gray-100 text-xs font-mono text-gray-800">@@ChildContent</code> with a 
                <code class="px-1.5 py-0.5 rounded bg-gray-100 text-xs font-mono text-gray-800">RenderFragment</code> on a layout page to share a sidebar between pages.
            </p>
        </div>
    </ChildContent>
</TwSidebar>

Data-driven navigation (programmatic)

Instead of hand-writing SidebarContent markup, pass a List<NavigationItem> to NavigationItems and TwSidebar renders the links, nested groups, and (with IsSearchable) a search box for you - this is exactly how this documentation site's own sidebar is built, see Navigation.razor.cs.
Set Icon on a NavigationItem to render a TwIcon before its label. It works on links and parent items at any depth. The icon is decorative and hidden from screen readers, so the label stays the item's name. It is styled by NavigationItemIcon on TwSidebarTheme.
RAZOR
<TwSidebar IsSidebarOpen="true" NavigationItems="_navigationItems" IsSearchable Style="background-color: #ffffff;">
    <HeaderContent>
        <a href="/sidebar/preview-navigation" class="flex items-center gap-2 px-4 py-3 border-b border-gray-200">
            <img src="_content/TwBlazor.Docs/images/logo.svg" alt="twblazor Logo" class="h-8 w-8 shrink-0" />
            <span class="text-xl font-bold tracking-tight text-gray-900">twblazor</span>
        </a>
    </HeaderContent>
    <ChildContent>
        <div class="p-6 max-w-2xl">
            <h2 class="text-lg font-semibold text-gray-900 mb-2">Data-Driven Navigation</h2>
            <p class="text-sm text-gray-600 leading-relaxed">
                This sidebar is generated entirely from a <code class="px-1.5 py-0.5 rounded bg-gray-100 text-xs font-mono text-gray-800">List&lt;NavigationItem&gt;</code>
                passed to <code class="px-1.5 py-0.5 rounded bg-gray-100 text-xs font-mono text-gray-800">NavigationItems</code> - no hand-written markup for links or groups. Try the search box above.
            </p>
        </div>
    </ChildContent>
</TwSidebar>
CSHARP
@code {
    private readonly List<NavigationItem> _navigationItems =
    [
        new() { Id = "dashboard", Label = "Dashboard", Href = "/dashboard", Icon = Icon.Speedometer2 },
        new()
        {
            Id = "content",
            Label = "Content",
            Icon = Icon.Collection,
            NavigationItems =
            [
                new() { Id = "posts", Label = "Posts", Href = "/posts" },
                new() { Id = "pages", Label = "Pages", Href = "/pages" },
                new() { Id = "media", Label = "Media", Href = "/media" },
            ]
        },
        new()
        {
            Id = "settings",
            Label = "Settings",
            Icon = Icon.Gear,
            NavigationItems =
            [
                new() { Id = "profile", Label = "Profile", Href = "/profile" },
                new() { Id = "security", Label = "Security", Href = "/security" },
            ]
        },
    ];
}

Item content

Use NavigationItemContent to render your own content after the label of the items generated from NavigationItems, such as a badge or a count. The template is called for every item and receives the NavigationItem as its context, so render nothing for the items that need no extra content. This documentation site uses it for the "New" badges in its own sidebar.
It works on parent items as well as links: on a parent item the content sits between the label and the chevron, as on "Content" below. A badge on a parent can stand for everything inside it, in place of a badge on every child.
Identify items by their Id or Href, not by reference, because the template receives a copy of the item while the sidebar is being searched. The content is placed inside the item's link or toggle button, so keep it non-interactive; any text in it is read out as part of the item's name. The wrapper around the content is styled by NavigationItemContent on TwSidebarTheme.
RAZOR
<TwSidebar IsSidebarOpen="true" NavigationItems="_navigationItems" Style="background-color: #ffffff;">
    <NavigationItemContent Context="item">
        @if (_badges.TryGetValue(item.Id ?? string.Empty, out var badge))
        {
            <TwChip Label="@badge" Color="Color.Info" Variant="ButtonVariant.Outlined" Size="ChipSize.Small" />
        }
    </NavigationItemContent>
    <ChildContent>
        <div class="p-6 max-w-2xl">
            <h2 class="text-lg font-semibold text-gray-900 mb-2">Item content</h2>
            <p class="text-sm text-gray-600 leading-relaxed">
                The badges beside "Inbox", "Content" and "Media" are rendered by one template, on link items and parent items alike.
            </p>
        </div>
    </ChildContent>
</TwSidebar>
CSHARP
@code {
    private readonly List<NavigationItem> _navigationItems =
    [
        new() { Id = "dashboard", Label = "Dashboard", Href = "/dashboard" },
        new() { Id = "inbox", Label = "Inbox", Href = "/inbox" },
        new()
        {
            Id = "content",
            Label = "Content",
            Collapsed = false,
            NavigationItems =
            [
                new() { Id = "posts", Label = "Posts", Href = "/posts" },
                new() { Id = "media", Label = "Media", Href = "/media" },
            ]
        },
    ];
    
    // Keyed by NavigationItem.Id, so the lookup still works while the sidebar is being searched.
    private readonly Dictionary<string, string> _badges = new()
    {
        ["inbox"] = "12",
        ["content"] = "New",
        ["media"] = "Beta",
    };
}

Keyboard navigation

The first Tab stop on the page is a link that skips the navigation. A closed sidebar is taken out of the Tab order entirely. On a narrow screen the sidebar opens over the page as a drawer: focus moves into it and the page behind it cannot be reached until it closes.
Key What it does
Tab From the top of the page: shows the "Skip to main content" link.
Enter On the skip link: moves focus to the main content.
Enter or Space On the sidebar button: opens or closes the sidebar.
Tab or Shift+ plus Tab Moves through the search field and the navigation items.
Enter or Space On a group: expands or collapses it.
Enter On a link: goes to that page.
Escape Closes the sidebar while it is open as a drawer, from wherever focus is, and returns focus to the sidebar button. In the search field the first press clears the text.
Enter or Space On the close button inside the drawer: closes it.

Theme configuration

Styling is controlled by TwBlazorTheme.Components (a TwSidebarTheme), configured via the AddTwBlazor() options callback described on the Get Started page. Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Property Type Controls
SkipLink string
DrawerCloseButton string
MobileOverlay string
MobileClosed string
MobileOpen string
NavigationList string
NavbarFixedInset string
NavbarNavigationResponsive string
NavbarNavigationExpanded string
Navbar string
NavbarContent string
NavbarBrand string
NavbarNavigation string
NavbarActions string
NavbarActionsCollapsible string
NavbarToggle string
NavbarToggleIcon string
NavbarLink string
NavbarLinkCollapsible string
NavbarLinkActive string
NavbarMobileMenu string
Sidebar string
MainContent string
MainContentRoot string
NavigationItemBase string
NavigationItemActive string
NavigationItemCurrent string
NavigationItemParent string
NavigationItemIcon string
NavigationItemContent string
NavigationDropdownContainer string
NavigationItemActiveLevelDeep string
NavigationDropdownContainerDeep string
NavigationGroupRailDeep string
NavigationItemToggleLabel string
NavigationItemToggleIcon string
Header string
Search string
SearchIcon string
SearchInput string
SearchInputVariant InputVariant?

Full reference: TwSidebarTheme on the API docs.

On this page

  • Basic sidebar
  • Data-driven navigation (programmatic)
  • Item content
  • Keyboard navigation
  • Theme configuration
twblazor

The Tailwind CSS component library for Blazor. Accessible, themeable and MIT licensed.

Discord (opens in a new tab) GitHub(opens in a new tab)

Get started

  • Install guide
  • Theming
  • Class merging
  • Localization

Guides

  • Tailwind CSS with Blazor
  • Why twblazor?
  • Right to left
  • AI agents and skills

Resources

  • API documentation (opens in a new tab)
  • llms.txt (opens in a new tab)
  • MIT License (opens in a new tab)

Community

  • Contributing (opens in a new tab)
  • Code of conduct (opens in a new tab)
  • Report an issue (opens in a new tab)

twblazor is and always will be free and open source.

An unhandled error has occurred. Reload