Skip to content

HyTopbar ​

Usage examples on this page are written for Lit / plain HTML (<hy-topbar>). The same component ships as HyTopbar in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A responsive top navigation bar component for application headers.

The topbar provides a structured container for branding, navigation, and actions at the top of an application. It renders a semantic <header> element with role="banner" for proper accessibility.

Key Features ​

  • Semantic <header> element with role="banner"
  • Three-slot layout: start, default (center), end
  • Fixed, sticky, or static positioning
  • Responsive height with CSS custom properties
  • Scroll-aware elevation and state changes
  • Built-in skip link support for bypass blocks
  • SSR compatible

Accessibility: built in ​

  • Renders semantic <header role="banner"> element
  • Skip link slot for bypass blocks
  • Proper landmark for screen readers
  • Focus management with visible focus indicators
  • High contrast mode support
  • Reduced motion support
  • Sets scroll-padding-top on the document while fixed or sticky, so focused elements are not hidden behind the bar: the bar's rendered height (kept current by a ResizeObserver, so it follows the design system's surface heights and the height override) plus a 16px margin. It restores whatever inline value it replaced, and never clears a value it did not write

Accessibility: your part ​

  • Put a skip link in the skip slot that points at the id of the main content.
  • Mark the link to the current page: selected on a hy-link variant="navigation", active on a hy-tab-nav-item.

Mobile Navigation ​

The default slot content is hidden on mobile (< 768px) to accommodate responsive layouts. To ensure navigation remains accessible on mobile devices, either:

  • Provide a hamburger menu in the start slot that reveals navigation
  • Add the show-content-mobile attribute to keep the default slot visible

Browser Compatibility ​

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • SSR support via Lit's isServer

When to use

  • The bar across the top of an application: the product's name, the page title, search and the account.
  • Navigation of two or three destinations.

Do

  • Keep it to what applies everywhere in the product.

When not to use

  • More than a few destinations: a hy-sidebar, keeping the topbar for identity and global actions.
  • Top-level destinations on a phone: hy-bottombar.
  • Controls for one view only: a hy-toolbar in that view, or the actions-start / actions-end slots of its hy-tab-group.

Examples ​

Basic Usage ​

html
<hy-topbar label="Main navigation">
  <a slot="start" href="/">Logo</a>
  <nav>Navigation links</nav>
  <div slot="end">Actions</div>
</hy-topbar>
html
<hy-topbar>
  <a slot="skip" href="#main-content" class="skip-link">Skip to content</a>
  <a slot="start" href="/">Logo</a>
  <nav>Links</nav>
</hy-topbar>
<main id="main-content">...</main>

Fixed Position with Elevation ​

html
<hy-topbar position="fixed" elevated>
  <span slot="start">Brand</span>
  <nav>Navigation</nav>
  <div slot="end">
    <button>Login</button>
  </div>
</hy-topbar>

Transparent Header ​

html
<hy-topbar transparent position="fixed">
  <a slot="start" href="/">Logo</a>
  <nav>Navigation</nav>
</hy-topbar>

API ​

Properties ​

PropertyAttributeTypeDefaultDescription
scrolledscrolledbooleanfalseWhether the page has been scrolled past the threshold
positionposition'fixed' | 'sticky' | 'static''fixed'CSS positioning of the topbar
sizesize'small' | 'medium' | 'large''medium'Size variant controlling the topbar height, read from the design system's surface heights (--hy-surface-height-sm|md|lg, overridable per size). - small: dense tool UIs, admin dashboards - medium: standard applications - large: marketing sites, landing pages
heightheightstring''Height override (escape hatch). Takes precedence over size.
elevatedelevatedbooleanfalseWhether the topbar has elevation (shadow)
borderedborderedbooleantrueWhether the topbar has a bottom border
transparenttransparentbooleanfalseWhether the topbar has a transparent background
collapsedcollapsedbooleanfalseWhether the topbar is collapsed/hidden
labellabelstring'Site header'Accessible name of the banner landmark. An empty value falls back to the default. Use for internationalization.
showContentMobileshow-content-mobilebooleanfalseWhether to show the default slot content on mobile devices

Events ​

EventDetailDescription
scroll—Emitted when scroll state changes. Detail: { scrolled: boolean }

Slots ​

SlotDescription
skipSkip link for keyboard users (bypass blocks)
startLeading content (logo, hamburger menu)
defaultMain/center content (navigation, title)
endTrailing content (actions, user menu, search)

CSS Parts ​

PartDescription
baseThe component's base wrapper element (the <header>)
containerThe inner container for content alignment
startThe start section wrapper
contentThe main/center content wrapper
endThe end section wrapper

CSS Custom Properties ​

The documented hooks. Every override hook the component reads — one per token it paints — is listed in @whitespaceux/harmony/theme-api.json, and @whitespaceux/harmony/component-bindings.json (the Harmony MCP get-bindings tool) says which part and state each one paints.

PropertyDefaultDescription
--hy-topbar-surface-height-smvar(--hy-surface-height-sm)Height for size="small"
--hy-topbar-surface-height-mdvar(--hy-surface-height-md)Height for size="medium"
--hy-topbar-surface-height-lgvar(--hy-surface-height-lg)Height for size="large"
--hy-topbar-background-surface-elevation-3var(--hy-background-surface-elevation-3)Background color. (same as surface-base in light mode; lifts in dark mode for OLED-true-black visibility)
--hy-topbar-border-elevated-restvar(--hy-border-elevated-rest)Bottom border color (the rim of the floating bar)
--hy-topbar-foreground-default-restvar(--hy-foreground-default-rest)Text/foreground color
--hy-topbar-padding-shell-inlinevar(--hy-padding-shell-inline)Horizontal padding
--hy-topbar-gap-shell-inlinevar(--hy-gap-shell-inline)Gap between sections
--hy-topbar-padding-layout-smvar(--hy-padding-layout-sm)Skip link block padding
--hy-topbar-padding-layout-mdvar(--hy-padding-layout-md)Skip link inline padding
--hy-topbar-radius-form-mdvar(--hy-radius-form-md)Skip link border radius
--hy-topbar-shadow-elevation-3var(--hy-shadow-elevation-3)Box shadow when elevated or scrolled
--hy-topbar-stroke-smvar(--hy-stroke-sm)Border width for bordered variant
--hy-topbar-motion-transition-enter-durationvar(--hy-motion-transition-enter-duration)Transition duration for the show and hide entrance animation
--hy-topbar-motion-transition-enter-easingvar(--hy-motion-transition-enter-easing)Transition easing for the show and hide entrance animation

Built with Lit. Documented with VitePress.