Skip to content

Site Header

The top bar: brand, links, dropdowns and mega panels, search, theme, account and a call to action. The panels share one box: it opens from under its item and, moving to the next, springs to the new size while the content slides across. Sticky with a blur once you scroll, and a drawer on small screens.

On this page
Used for
  • Marketing site top bar
  • Docs header with search
  • App header with account
  • Mobile menu drawer

Examples

Minimal

Installation

npx knowns-ui@latest add site-header
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

brand / brandHref / brandLabel
ReactNode / string
Default"/"
Logo and name, a link home named "<brandLabel> home". On the home page itself, or in a preview frame (HomeFrame), it scrolls back to the top instead and clears the hash.
onHome
() => void
For an app that switches views in place: the brand calls it (and scrolls to the top) instead of following brandHref.
nav
NavEntry[]
Default[]
Links, { kind: "dropdown", items } and { kind: "mega", groups, featured, cards, footer, drawer }. cards are product cards (image, imageDark, label, description, href) in a row under the groups, or the whole panel with no groups. Items take a description, an icon, a count and a badge. footer is a quiet row at the bottom of the panel (text and a link). drawer: "flat" lists the groups in the mobile drawer instead of folding them.
currentHref
string
Marks the matching top item with an indicator and the exact link with aria-current. Parents match their sub-paths.
onNavigate
(href, event) => void
Every link click; call preventDefault for client-side routing.
search
{ onOpen, label?, shortcut?, button? }
A search button (⌘K hint from 1024px) and a Search row in the drawer. Open your Command Menu in onOpen. button: false drops the bar button and keeps the drawer row.
leading
ReactNode
Before the brand, e.g. a SidebarTrigger that opens your app or docs navigation on small screens.
theme
{ value: "light" | "dark", onChange }
Our Theme Toggle: the new theme grows from the click in a circle (instant with reduced motion). 44px on touch.
actions
ReactNode
Icon buttons right after the theme toggle, in its spacing: a GitHub link, notifications. Use the ghost icon Button so they match the toggle.
account / signIn / cta
ReactNode / { label?, href?, onClick? }
Right side: your UserMenu when signed in, otherwise Sign in; the CTA is primary on marketing.
variant
"marketing" | "minimal"
Default"marketing"
64px with centred links, or 52px with links next to the brand.
sticky / scrollRoot
boolean / HTMLElement
Defaulttrue / window
Sticky with a blurred background and hairline after 4px of scroll; pass the scrolling element when it is not the window.
solid
boolean
Defaultfalse
Always show the background and hairline, for app and docs layouts where the header sits on a sidebar.

Keyboard: Tab reaches each top item; ← → move between them, ↓ opens a panel and enters it, ↑ ↓ move through its links (↑ from the first returns to the button), Escape closes and gives focus back. On a mouse, panels open on hover after a short pause. Below 768px the links move to a drawer: a modal dialog, so focus stays inside and Escape closes it; groups are accordions, the page behind does not scroll, and the drawer closes if the window grows past the breakpoint.

What it handles

  1. 01Sticks to the top, transparent at first, and adds a blurred background and a hairline once the page scrolls past 4px, or always with solid.
  2. 02Marks the current page from currentHref with an underline indicator and aria-current, and calls onNavigate for every link so you can route on the client.
  3. 03Opens dropdowns and a mega panel of grouped links with icons, descriptions and a featured card, by click, by hover on a mouse, or by the arrow keys.
  4. 04Moves by keyboard: left and right between top items, down into a panel, up and down through its links, Home and End to the ends, and Escape to close and return focus.
  5. 05Moves the links into a modal dialog drawer below 768px, with accordion groups, a locked page scroll and focus kept inside.
  6. 06Shows a search trigger with a kbd hint, a theme toggle, extra icon actions, an account slot or a Sign in link, and a call to action, in a marketing or a minimal variant.

States

First render
Nothing. The bar paints in its resting look
none
Scrolled
The background blurs and the hairline appears
180ms, ease out
Panel open or close
The panel fades and slides down a few pixels
120ms, ease out
Chevron and active indicator
The chevron turns over and the underline fades and widens
180ms, ease out
Link hover
The text and background colour change
120ms, ease out
Drawer opens
The drawer slides in from the right edge
280ms, ease out
Reduced motion
Panels, indicator and drawer change at once
0ms

Works with

When to use

When to use

  • The top bar of a marketing site or app: links, a mega panel for products, search, theme, account and a call to action.
  • Sites that need a proper small-screen menu: a drawer with grouped links, focus kept inside and the page locked behind it.

When not to use

  • The title row of one app page, with breadcrumbs and actions: use Page Header.
  • Navigation between sections of a settings area: use Settings.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Site Header to my app and wire it to my own data.
  • I need the top bar of a marketing site or app: links, a mega panel for products, search, theme, account and a call to action. Set that up with the Knowns UI Site Header.
  • Which Site Header props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "site-header" }) and search_docs({ query: "site header" }).

Need help?

Stuck on Site Header, or found something off? We read every message.