Header
A site header with a title, links, actions and a mobile menu that opens in a slideover.
On this page
Examples
Header
The mobile menu is a native dialog handled in the browser: it works in static rendering and closes when a link is followed.
Page content. Narrow the window below the lg breakpoint to get the menu button.
Razor
<div class="w-full overflow-hidden rounded-xl border border-(--klyroo-border)">
<KlyHeader Title="Acme" Items="_items" Sticky="false" AriaLabel="Site" MenuTitle="Site menu" data-testid="header">
<Right>
<KlyButton Label="Sign in" Size="KlySize.Sm" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" />
</Right>
</KlyHeader>
<p class="p-6 text-sm text-(--klyroo-text-muted)">Page content. Narrow the window below the lg breakpoint to get the menu button.</p>
</div>
@code {
private static readonly KlyNavigationItem[] _items =
[
new("Home") { Href = "/", Exact = true },
new("Components")
{
Children =
[
new("Button") { Href = "/components/button" },
new("Header") { Href = "/components/header" },
new("Sidebar") { Href = "/components/sidebar" },
],
},
new("Docs") { Href = "/docs" },
];
}Custom slots
Left, center, right and the mobile body are all replaceable.
Razor
<div class="w-full overflow-hidden rounded-xl border border-(--klyroo-border)">
<KlyHeader Sticky="false" MenuTitle="Product menu" MenuSide="SlideoverSide.Left" data-testid="header-custom">
<Left>
<a href="/" class="inline-flex items-center gap-2 font-mono text-sm font-semibold text-(--klyroo-text-highlighted)">
<Logo Class="size-6" />
<span>acme/app</span>
</a>
</Left>
<ChildContent>
<nav aria-label="Product" class="flex items-center gap-5 text-sm text-(--klyroo-text-muted)">
<a href="/components/header" class="hover:text-(--klyroo-text-highlighted)">Features</a>
<a href="/components/footer" class="hover:text-(--klyroo-text-highlighted)">Pricing</a>
<a href="/docs" class="hover:text-(--klyroo-text-highlighted)">Changelog</a>
</nav>
</ChildContent>
<Right>
<KlyColorModeButton />
<KlyButton Label="Get started" Size="KlySize.Sm" />
</Right>
<Body>
<nav aria-label="Product menu" class="flex flex-col gap-3 text-sm">
<a href="/components/header" class="text-(--klyroo-text)">Features</a>
<a href="/components/footer" class="text-(--klyroo-text)">Pricing</a>
<a href="/docs" class="text-(--klyroo-text)">Changelog</a>
</nav>
</Body>
</KlyHeader>
</div>API
KlyHeader
Site header with a title or logo, links and actions. On small screens the links move into a slideover menu.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the Items navigation. Needed when the page has several. | |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Href |
string |
"./" |
Where the title link goes. The default "./" is the home of the app: relative to <base href> , so it is right below a path base too. |
Items |
IReadOnlyList |
Site links: a horizontal navigation in the middle, and a vertical one in the mobile menu. Set ChildContent or Body to replace either. | |
Menu |
bool |
true |
Shows the mobile menu button below the lg breakpoint, when there is something to put in the menu. |
MenuSide |
SlideoverSide |
SlideoverSide. |
The edge the mobile menu slides in from. Values: Right, Left, Top, Bottom. |
MenuTitle |
string |
Title of the mobile menu panel. Defaults to the built-in text. | |
Sticky |
bool |
true |
Keeps the header at the top of the screen while the page scrolls. |
Title |
string |
The title link on the left, used when Left is not set. | |
Ui |
HeaderUi |
Per-instance class overrides of the slots of the header, see HeaderUi . They are merged after the theme and the Class parameter wins on the root slot. |
Slots
| Name | Type | Description |
|---|---|---|
Body |
RenderFragment |
Content of the mobile menu. Replaces the vertical Items navigation. |
Left |
RenderFragment |
Replaces the title link: a logo, or a logo with the title. |
Right |
RenderFragment |
The right side: actions, color mode button, language select. Always visible. |
ChildContent |
RenderFragment |
The middle of the header, shown from the lg breakpoint up. Replaces the Items navigation. |
Ui slots
Ui takes a HeaderUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyHeader , after the theme and the app configuration. |
Container |
Classes merged into the container slot of KlyHeader , after the theme and the app configuration. |
Left |
Classes merged into the left slot of KlyHeader , after the theme and the app configuration. |
Title |
Classes merged into the title slot of KlyHeader , after the theme and the app configuration. |
Center |
Classes merged into the center slot of KlyHeader , after the theme and the app configuration. |
Right |
Classes merged into the right slot of KlyHeader , after the theme and the app configuration. |
Menu |
Classes merged into the menu slot of KlyHeader , after the theme and the app configuration. |