Navigation
Navbar
Free24.9 KB gzippedThe top header of an app or site. Renders a <header> (a banner landmark when it isn't inside main, article, aside, nav, or section) with brand, navigation, and actions. Below collapseBelow the navigation moves into a modal drawer opened by a menu button.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space and 1 more · Full report
Import
import { Navbar } from "@vjdesigns/vjdesigns-ui";
Importing only Navbar adds about 24.9 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Brand, navigation and actions. Below collapseBelow the links move into a drawer opened by a menu button. Resize your window to see it. Pass your router's link component as as.
import { useState } from "react";
import { Avatar, Box, Button, Navbar } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [page, setPage] = useState("overview");
const link = (id: string, label: string) => (
<Navbar.Link
href={`#${id}`}
active={page === id}
onClick={(event) => {
event.preventDefault();
setPage(id);
}}
>
{label}
</Navbar.Link>
);
return (
<Box radius="lg" border overflow="hidden" style={{ width: "100%" }}>
<Navbar position="static" contained={false} collapseBelow="md" menuTitle="Acme">
<Navbar.Brand href="#example-basic">Acme</Navbar.Brand>
<Navbar.Nav aria-label="Example">
{link("overview", "Overview")}
{link("projects", "Projects")}
{link("reports", "Reports")}
</Navbar.Nav>
<Navbar.Actions>
<Button size="sm" variant="ghost" tone="neutral">
Help
</Button>
<Avatar name="Jordan Lee" size="sm" colorFromName />
</Navbar.Actions>
</Navbar>
</Box>
);
}
Solid
variant="solid" fills the bar with the primary color.
import { Box, Navbar } from "@vjdesigns/vjdesigns-ui";
export function Solid() {
return (
<Box radius="lg" overflow="hidden" style={{ width: "100%" }}>
<Navbar position="static" variant="solid" contained={false} size="sm" collapseBelow="sm" menuTitle="Northwind">
<Navbar.Brand href="#example-solid">Northwind</Navbar.Brand>
<Navbar.Nav align="end" aria-label="Solid example">
<Navbar.Link href="#example-solid" active>
Home
</Navbar.Link>
<Navbar.Link href="#example-solid">Pricing</Navbar.Link>
<Navbar.Link href="#example-solid">About</Navbar.Link>
</Navbar.Nav>
</Navbar>
</Box>
);
}
Groups
Navbar.Group puts links under one button that opens a dropdown, or an expandable section in the mobile menu. It's a disclosure, not a menu, so its links stay ordinary links in the Tab order. Escape, a press outside, tabbing out or choosing a link closes it, and opening one group closes the other. active marks the group that holds the current page.
import { useState } from "react";
import { Box, Navbar } from "@vjdesigns/vjdesigns-ui";
export function Groups() {
const [page, setPage] = useState("season");
const link = (id: string, label: string) => (
<Navbar.Link
href={`#${id}`}
active={page === id}
onClick={(event) => {
event.preventDefault();
setPage(id);
}}
>
{label}
</Navbar.Link>
);
return (
<Box radius="lg" border style={{ width: "100%" }}>
<Navbar position="static" contained={false} collapseBelow="md" menuTitle="Acme">
<Navbar.Brand href="#example-groups">Acme</Navbar.Brand>
<Navbar.Nav aria-label="Groups example">
{link("home", "Home")}
<Navbar.Group label="Reports" active={page === "season" || page === "players"}>
{link("season", "Season")}
{link("players", "Players")}
</Navbar.Group>
<Navbar.Group label="Teams" active={page === "varsity" || page === "jv"}>
{link("varsity", "Varsity")}
{link("jv", "Junior varsity")}
</Navbar.Group>
</Navbar.Nav>
</Navbar>
</Box>
);
}
Badges
badge on Navbar.Link or Navbar.Group shows a count (capped at 99+, hidden at 0) or a short text after the label, in the bar and the mobile menu. badgeLabel gives screen readers the full meaning ("Messages, 3 unread messages"). On the solid bar, a badge without a badgeTone swaps the bar's colors so it stands out in both themes.
import { Box, Flex, Navbar } from "@vjdesigns/vjdesigns-ui";
export function Badges() {
return (
<Flex direction="column" gap={3} style={{ width: "100%" }}>
{(["surface", "solid"] as const).map((variant) => (
<Box key={variant} radius="lg" border={variant === "surface"} overflow="hidden">
<Navbar position="static" variant={variant} contained={false} size="sm" collapseBelow="sm" menuTitle="Acme">
<Navbar.Brand href="#example-badges">Acme</Navbar.Brand>
<Navbar.Nav aria-label={`Badges example, ${variant}`}>
<Navbar.Link href="#example-badges" active>
Home
</Navbar.Link>
<Navbar.Link href="#example-badges" badge={3} badgeLabel="3 unread messages">
Messages
</Navbar.Link>
<Navbar.Link href="#example-badges" badge={120} badgeTone="danger" badgeLabel="120 alerts">
Alerts
</Navbar.Link>
<Navbar.Link href="#example-badges" badge="New">
Playbook
</Navbar.Link>
</Navbar.Nav>
</Navbar>
</Box>
))}
</Flex>
);
}
Active tone
activeTone colors the active link's pill and indicator bar: "accent" (the default), "primary" to follow the brand, or "neutral" for a quieter gray.
import { Box, Flex, Navbar } from "@vjdesigns/vjdesigns-ui";
export function ActiveTone() {
return (
<Flex direction="column" gap={3} style={{ width: "100%" }}>
{(["accent", "primary", "neutral"] as const).map((tone) => (
<Box key={tone} radius="lg" border overflow="hidden">
<Navbar position="static" contained={false} size="sm" collapseBelow="sm" menuTitle={tone} activeTone={tone}>
<Navbar.Brand href="#example-active-tone">{tone}</Navbar.Brand>
<Navbar.Nav aria-label={`${tone} example`}>
<Navbar.Link href="#example-active-tone" active>
Home
</Navbar.Link>
<Navbar.Link href="#example-active-tone">Pricing</Navbar.Link>
<Navbar.Link href="#example-active-tone">About</Navbar.Link>
</Navbar.Nav>
</Navbar>
</Box>
))}
</Flex>
);
}
Accessibility
Every Navbar.Nav is a navigation landmark: give each one a distinct aria-label so landmark lists read "Primary" and "Account" rather than "navigation" twice. active sets aria-current="page", and below collapseBelow the menu button (named by menuLabel) opens the links in a drawer named by menuTitle.
import { useState } from "react";
import { Box, Navbar } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [page, setPage] = useState("docs");
const link = (id: string, label: string) => (
<Navbar.Link
href={`#${id}`}
active={page === id}
onClick={(event) => {
event.preventDefault();
setPage(id);
}}
>
{label}
</Navbar.Link>
);
return (
<Box radius="lg" border overflow="hidden" style={{ width: "100%" }}>
<Navbar position="static" contained={false} collapseBelow="lg" menuTitle="Acme menu" menuLabel="Open the Acme menu">
<Navbar.Brand href="#example-accessibility">Acme</Navbar.Brand>
<Navbar.Nav aria-label="Primary">
{link("docs", "Docs")}
{link("blog", "Blog")}
</Navbar.Nav>
<Navbar.Nav aria-label="Account" align="end">
{link("signin", "Sign in")}
</Navbar.Nav>
</Navbar>
</Box>
);
}
Translated
The menu button's name and the drawer's close button come from the locale (Spanish here); the links and the drawer's title are your own text. Make the window narrow to open the drawer.
import { Box, Navbar, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import es from "@vjdesigns/vjdesigns-ui/locales/es";
export function Translated() {
return (
<LocaleProvider locale="es" messages={es}>
<Box radius="lg" border overflow="hidden" style={{ width: "100%" }}>
<Navbar position="static" contained={false} collapseBelow="lg" menuTitle="Menú de Acme">
<Navbar.Brand href="#example-translated">Acme</Navbar.Brand>
<Navbar.Nav aria-label="Principal">
<Navbar.Link href="#example-translated" active>
Inicio
</Navbar.Link>
<Navbar.Link href="#example-translated">Productos</Navbar.Link>
<Navbar.Link href="#example-translated">Contacto</Navbar.Link>
</Navbar.Nav>
</Navbar>
</Box>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
<Navbar>
<Navbar.Brand href="/">Hoops</Navbar.Brand>
<Navbar.Nav>
<Navbar.Link href="/" active>Home</Navbar.Link>
<Navbar.Link href="/teams">Teams</Navbar.Link>
</Navbar.Nav>
<Navbar.Actions>
<Button size="sm">Sign in</Button>
</Navbar.Actions>
</Navbar>
API reference
Navbar
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
variantVisual style. See | "surface""transparent""solid" | "surface" |
sizeBar height, link size, and menu button size. sm 56px, md 64px, lg 80px tall. | "sm""md""lg" | "md" |
position
| "static""sticky""fixed" | "sticky" |
reserveScrollPaddingKeeps focused and scrolled-to content clear of a | boolean | true |
borderedDraws a hairline under the bar. | boolean | false |
elevatedAlways shows a soft shadow under the bar. | boolean | false |
elevateOnScrollShows the soft shadow only once the window has scrolled (a passive, frame-throttled listener). A | boolean | false |
containedCenters the content in a max-width | boolean | true |
maxWidthMax width of the content when | "xs""sm""md""lg""xl""2xl""full""prose" | "xl" |
collapseBelowBelow this breakpoint (sm 640px, md 768px, lg 1024px), | "sm""md""lg" | "md" |
openControlled open state of the mobile menu. | boolean | — |
defaultOpenInitial open state of the mobile menu when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state whenever the mobile menu opens or closes. | (open: boolean) => void | — |
menuLabelAccessible name of the menu button. Localize it here. | string | "Open menu" |
menuTitleTitle of the mobile menu drawer (it names the dialog). | ReactNode | "Menu" |
menuSideEdge the mobile menu slides in from. | "start""end" | "end" |
activeToneNew in 1.4.10Color of the active link's pill and indicator bar, in the bar and the mobile menu: | "accent""primary""neutral" | "accent" |
Also accepts native <header> attributes, plus className, style and ref.
Navbar.Brand
The logo or product name at the start of the bar, usually a link home.
| Prop | Type | Default |
|---|---|---|
asComponent or element to render. Defaults to | ElementType | — |
childrenLogo and/or product name. A logo-only brand link needs an | ReactNode | — |
Navbar.Nav
| Prop | Type | Default |
|---|---|---|
children
| ReactNode | — |
alignWhere the links sit in the bar, between the brand and the actions: | "start""center""end" | "start" |
gapSpace between the links in the bar, as a spacing step ( | Responsive<Space> | 1 |
aria-labelNames the navigation landmark. Give each | string | "Main" |
Also accepts native <nav> attributes, plus className, style and ref.
Navbar.Item
| Prop | Type | Default |
|---|---|---|
childrenA | ReactNode | — |
showInWhere the item appears. | "both""bar""drawer" | "both" |
Also accepts native <li> attributes, plus className, style and ref.
Navbar.Link
A primary navigation link. Wraps itself in an <li> unless it's already inside Navbar.Item. In the mobile drawer, clicking it closes the drawer (even if a router prevents the default navigation).
It renders once in the bar and once in the drawer (only one is ever exposed), so don't give it an id. A ref attaches to the bar's copy.
| Prop | Type | Default |
|---|---|---|
asComponent or element to render. Defaults to | ElementType | — |
activeMarks the link as the current page: sets | boolean | false |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
badgeNew in 2.4.0A count (rendered with | NavbarBadgeValue | — |
badgeLabelNew in 2.4.0Screen-reader text for the badge, e.g. "3 unread messages". Replaces the visible badge text in the accessible name. | string | — |
badgeToneNew in 2.4.0Badge color. By default | "neutral""primary""accent""success""warning""danger""info" | — |
childrenThe visible label. | ReactNode | — |
Navbar.Group
New in 2.4.0| Prop | Type | Default |
|---|---|---|
labelRequiredThe group button's visible label, and its accessible name. | ReactNode | — |
iconDecorative icon before the label. | ReactNode | — |
childrenThe group's | ReactNode | — |
activeOne of the group's links is the current page. The button then shows the active look (it doesn't set | boolean | false |
badgeA count or short text on the group button, like | NavbarBadgeValue | — |
badgeLabelScreen-reader text for the badge. | string | — |
badgeToneBadge color. Same default as | "neutral""primary""accent""success""warning""danger""info" | — |
openControlled open state of the dropdown in the bar. | boolean | — |
defaultOpenInitial open state of the dropdown when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state of the dropdown in the bar. | (open: boolean) => void | — |
disabledDisables the group button. | boolean | false |
Also accepts native <li> attributes, plus className, style and ref.
Navbar.Actions
| Prop | Type | Default |
|---|---|---|
childrenButtons, an avatar, a theme toggle, a search field. Stays visible at every width, so keep it short on phones. | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Navbar targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves through the brand link, the links and the actions. |
| EnterSpace | On the menu button (narrow screens): opens the links in a drawer. On a Navbar.Group button: opens or closes its links. |
| Escape | Closes the drawer, or an open group's dropdown and returns focus to its button. |
The drawer traps focus while open; on close, focus returns to the menu button. A group's dropdown doesn't trap focus: its links stay in the Tab order, and Tab past the last one closes it. Opening one group closes the others.
Roles and states
| Element | Role | States and properties |
|---|---|---|
<header> | banner (at the page's top level) | — |
Navbar.Nav | navigation | aria-label; links in a list |
| Active link | link | aria-current="page" |
| Menu button | button | aria-label, aria-haspopup="dialog", aria-expanded |
Navbar.Group button | button | aria-expanded, aria-controls (the open list). A disclosure, not a menu |
| Link badge | none | Part of the link's name ("Messages 3"), or badgeLabel in its place |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |