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 Features

  • 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 CSS custom property to prevent focus obscuring

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

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. - small: 48px — dense tool UIs, admin dashboards - medium: 64px — standard applications - large: 112px — 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''Accessible label for the topbar
showContentMobileshow-content-mobilebooleanfalseWhether to show the default slot content on mobile devices

Events

EventDetailDescription
scrollEmitted 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

PropertyDescription
--hy-topbar-height-smHeight for size="small" (default: --hy-surface-height-sm)
--hy-topbar-height-mdHeight for size="medium" (default: --hy-surface-height-md)
--hy-topbar-height-lgHeight for size="large" (default: --hy-surface-height-lg)
--hy-topbar-background-surface-elevationBackground color. Default: --hy-background-surface-elevation-3 (same as surface-base in light mode; lifts in dark mode for OLED-true-black visibility)
--hy-topbar-border-default-restBottom border color (default: --hy-border-default-rest)
--hy-topbar-foreground-default-restText/foreground color (default: --hy-foreground-default-rest)
--hy-topbar-padding-inlineHorizontal padding (default: --hy-padding-shell-inline)
--hy-topbar-section-gapGap between sections (default: --hy-gap-shell-inline)
--hy-topbar-skip-padding-blockSkip link block padding (default: --hy-padding-layout-sm)
--hy-topbar-skip-padding-inlineSkip link inline padding (default: --hy-padding-layout-md)
--hy-topbar-skip-radiusSkip link border radius (default: --hy-radius-form-md)
--hy-topbar-focus-radiusFocus indicator border radius (default: --hy-focus-ring-radius)
--hy-topbar-shadow-elevationBox shadow when elevated or scrolled
--hy-topbar-strokeBorder width for bordered variant
--hy-topbar-enter-durationTransition duration for the show and hide entrance animation
--hy-topbar-enter-easingTransition easing for the show and hide entrance animation

Built with Lit. Documented with VitePress.