Showcase

Blazor Navbar

The Blazor Bootstrap Navbar component is a responsive navigation header with a brand, links, dropdowns, forms, and text, which collapses behind a toggler or into an offcanvas panel. The examples below cover brand, nav, forms, text and color schemes.
API Documentation
INFO
Navbar follows the Bootstrap 5.3 navbar. It collapses its menu behind a toggler below ExpandBreakpoint (Large by default), so resize the window to see the collapsed menu. The collapse, offcanvas, and dropdowns use the Bootstrap JavaScript bundle the app already loads.

Basic usage #

A navbar holds a brand, navigation links, dropdowns, and forms, and collapses them behind a toggler on small screens.
How to use:
  1. Add Navbar with an AriaLabel and a BackgroundColor.
  2. Put a NavbarBrand in the Brand slot.
  3. Put the menu in ChildContent: a NavbarNav with NavbarItem and NavbarDropdown components, and any form.
  4. Give a search form role="search".
The item matching the current URL is active and marked aria-current="page".

Brand #

The brand can be a link, plain text, an image, or an image with text.
How to use:
  1. Set Href for a link; leave it unset for plain text.
  2. Set ImageSrc, ImageWidth, and ImageHeight for an image.
  3. Set ImageAlt to the brand name when the image is shown alone, or to an empty string when text follows it.
Navigation links, disabled links, and dropdowns.
How to use:
  1. Add NavbarItem with Href. Set Match="NavLinkMatch.All" on a home link so it is not active on every page.
  2. Set Disabled="true" to disable a link.
  3. Add NavbarDropdown with Text, holding DropdownItem, DropdownHeader, and DropdownDivider components.

Forms #

Place a search form, an input group, or buttons in the navbar.
How to use:
  1. Put the form in ChildContent. Use class="d-flex" to keep its controls on one line.
  2. Use InputGroup for add-ons, and Button for actions.
These navbars set ExpandBreakpoint="NavbarExpand.Always", so they never collapse.

Text #

Add text that is vertically centered and colored for the navbar.
How to use:
  1. Add NavbarText in ChildContent.
Change the display name and press Tab to update the text. It is rendered as text, never as HTML.

Color schemes #

Pair a background with a light or dark theme.
How to use:
  1. Set BackgroundColor (a bg-* class) or Color (a text-bg-* class), or a custom background with Style.
  2. Set Theme="NavbarTheme.Dark" on dark backgrounds, so the text is light, and NavbarTheme.Light on light ones.

Containers #

The navbar's contents are fluid by default. Wrap the navbar in a container, or limit its contents to a container width.
How to use:
  1. Set Container to NavbarContainer.Default for a centered container, or to a breakpoint for a responsive container.

Placement #

Place the navbar in the page flow, fix it to the top or bottom of the viewport, or make it sticky.
How to use:
  1. Set Placement. A fixed navbar leaves the page flow, so add padding to the body to keep content from going under it.
Pick a placement and scroll the box. The demo box stands in for the viewport.

Responsive behaviors #

Choose when the menu collapses and where the toggler goes.
How to use:
  1. Set ExpandBreakpoint. Never keeps the menu collapsed at every width; Always never collapses it.
  2. Set TogglerPosition="NavbarTogglerPosition.Start" to put the toggler before the brand.
  3. Set BrandInCollapse="true" to hide the brand until the menu expands.
Narrow the window below 992px to see the first three collapse.

Scrolling #

Let a long collapsed menu scroll instead of growing.
How to use:
  1. Set Scrollable="true" on NavbarNav, and ScrollHeight to its maximum height (75vh by default).

External content #

Show and hide content that lives outside the navbar.
How to use:
  1. Add a Collapse with an Id.
  2. Set ExternalCollapseId on the navbar to that id. The toggler then controls the collapse, and focus moves into it when it opens.
  3. Set ExpandBreakpoint="NavbarExpand.Never" so the toggler shows at every width.

Offcanvas #

Show the collapsed menu in an offcanvas panel.
How to use:
  1. Set CollapseMode="NavbarCollapseMode.Offcanvas" and an OffcanvasTitle.
  2. Set OffcanvasPlacement to choose the side it opens from; the default is the end.
  3. Above ExpandBreakpoint the menu shows inline, as a regular navbar. Use NavbarExpand.Never to keep the offcanvas at every width.
The first navbar is a responsive offcanvas; the second always uses a dark offcanvas.

Methods #

Show, hide, or toggle the collapsed menu from code.
How to use:
  1. Get a reference with @ref, and call ShowAsync, HideAsync, or ToggleAsync.
  2. The methods do nothing while the navbar is expanded.
  3. Parameters such as CollapseMode can change at runtime; the methods keep working on the new menu.

Close after navigation #

The collapsed menu closes by itself after a navigation, so the new page is not hidden behind it.
Open the menu and pick a view. The menu closes, and the picked view becomes the active item.
Use the navbar as the top bar of a layout with a Sidebar.
How to use:
  1. Put the navbar at the top of main, beside the Sidebar, with Placement="NavbarPlacement.StickyTop".
  2. The navbar uses Bootstrap's own sticky (1020) and fixed (1030) z-index, which matches the layout's sticky header.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.