Organisms · Navbar
Navbar
The top of a page: the brand, the main links and a few actions. When its container gets narrow, the links move into a menu sheet. Nothing gets cut off, and nothing is hidden for good.
- Best for
- The top of a site: the brand, up to about six main links and a few actions.
- Not for
- App navigation across many grouped pages: use Sidebar.
This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).
Examples
Store navigation
Code
tsx
const ITEMS = [ { label: 'Replicas', href: '#replicas' }, { label: 'Optics', href: '#optics', current: true }, { label: 'Parts', href: '#parts' }, { label: 'Care', href: '#care' }, { label: 'Field notes', href: '#field-notes' },]const BRAND = ( <a href="#home" className="inline-flex items-center min-h-10 font-display font-bold uppercase tracking-[0.14em] text-[var(--color-text-primary)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-focus-ring)]" > Hexline </a>)const ACTIONS = ( <> <IconButton label="Search" variant="ghost"> <Search aria-hidden="true" className="w-5 h-5" /> </IconButton> <IconButton label="Cart, 2 items" variant="ghost" asChild> <a href="#cart"> <ShoppingBag aria-hidden="true" className="w-5 h-5" /> </a> </IconButton> </>)<Navbar label="Store navigation" brand={BRAND} items={ITEMS} actions={ACTIONS} />A menu among the links
Code
tsx
const ITEMS = [ { label: 'Replicas', href: '#replicas' }, { label: 'Optics', href: '#optics', current: true }, { label: 'Parts', href: '#parts' }, { label: 'Care', href: '#care' }, { label: 'Field notes', href: '#field-notes' },]const BRAND = ( <a href="#home" className="inline-flex items-center min-h-10 font-display font-bold uppercase tracking-[0.14em] text-[var(--color-text-primary)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-focus-ring)]" > Hexline </a>)const ACTIONS = ( <> <IconButton label="Search" variant="ghost"> <Search aria-hidden="true" className="w-5 h-5" /> </IconButton> <IconButton label="Cart, 2 items" variant="ghost" asChild> <a href="#cart"> <ShoppingBag aria-hidden="true" className="w-5 h-5" /> </a> </IconButton> </>)<Navbar label="Store navigation with a menu" brand={BRAND} items={[ ...ITEMS.slice(0, 3), { label: 'Guides', menu: [ { label: 'Sizing', href: '#sizing', description: 'Fit charts for every replica.' }, { label: 'Returns', href: '#returns', description: 'Thirty days, no questions.' }, ], }, ]} actions={ACTIONS}/>A narrow container
Code
tsx
const ITEMS = [ { label: 'Replicas', href: '#replicas' }, { label: 'Optics', href: '#optics', current: true }, { label: 'Parts', href: '#parts' }, { label: 'Care', href: '#care' }, { label: 'Field notes', href: '#field-notes' },]const BRAND = ( <a href="#home" className="inline-flex items-center min-h-10 font-display font-bold uppercase tracking-[0.14em] text-[var(--color-text-primary)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--color-focus-ring)]" > Hexline </a>)const ACTIONS = ( <> <IconButton label="Search" variant="ghost"> <Search aria-hidden="true" className="w-5 h-5" /> </IconButton> <IconButton label="Cart, 2 items" variant="ghost" asChild> <a href="#cart"> <ShoppingBag aria-hidden="true" className="w-5 h-5" /> </a> </IconButton> </>)<div className="max-w-sm"> <Navbar label="Store navigation, narrow" brand={BRAND} items={ITEMS} actions={ACTIONS} /></div>Anatomy
| Part | What it is |
|---|---|
| Header | The page's banner landmark, a region screen readers can jump straight to, at the top level of the page. |
| Brand | The wordmark or logo, usually a link to the home page. |
| Links | A named navigation region. The current page sits on the neutral selected surface with a 2px signal underline, plus aria-current, an ARIA attribute (Accessible Rich Internet Applications, the labels screen readers rely on) that tells screen readers this is the page you are on. |
| Actions | They stay visible at every width. |
| Menu | When the container is narrower than 42rem (rem is a unit based on the root text size, usually 16 pixels), an icon button opens the same links in a Sheet. If the container widens past that breakpoint while the sheet is open, the sheet stays open. It doesn't close itself when the links reappear in the bar. |
Props
- labelstring
- Required. The name screen readers give the navigation region.
- brandReactNode
- Required. The wordmark or logo, usually a link to the home page.
- itemsNavbarItem[]
- Required. A link is { label, href, current }. A menu among the links is { label, menu, current }: menu lists { label, href, description } entries, opened from a dropdown on a wide bar and listed as a labelled group in the menu sheet on a narrow one.
- actionsReactNode
- Controls on the right: icon buttons, a cart link, an account menu. Keep them small, because they stay visible at every width.
- renderLink(props: LinkRenderProps) => ReactNodeDefault a plain anchor
- Pass your router's link component here. Map href to its own prop, and pass className, aria-current and onClick through.
- menuLabelstringDefault 'Menu'
- The menu button's name for screen readers, and the sheet's title.
- menuFooterReactNode
- Shown in the menu sheet under the links. Use it for an action that doesn't fit in actions on a narrow bar. Hide the matching copy in actions below the breakpoint by wrapping it in an element with the classes hidden @2xl:flex (hidden @4xl:flex when collapseBelow is '4xl').
- collapseBelow'2xl' | '4xl'Default '2xl'
- The bar's own width below which the links fold into the menu sheet: 2xl is 42rem, 4xl is 56rem. Pick the one at which the brand, every link and the actions still fit on one row with room to spare.
- classNamestring
- Added to the root classes. Where two Tailwind utility classes clash, the later one wins.
- refRef<HTMLElement>
- The header element.
Keyboard
| Keys | Result |
|---|---|
| Tab | Moves through the brand, each link and the actions, then the menu button when it shows. |
| Enter | Follows a link, or opens the menu. |
| Esc | Closes the menu and sends focus back to its button. |
Do and don't
Do
- Mark exactly one item as current.
- Keep actions to icon buttons with names, or one short button.
- If a page has more than one navbar, give each its own label.
Don't
- Don't put more than about six links in the bar. Group the rest under a page.
- Don't hide an action inside the menu that the bar shows at wide widths only.
- Don't mark a link as current with colour alone. The selected surface, the underline and aria-current all move with it.