Skip to content
Focsd homeFocsd homeFocsd
Forms

Header / top bar

The top bar of an app or site: brand, navigation and actions. Collapses to a menu button on small screens.

  • Tag: focsd-header
  • Pattern: Banner landmark
  • Category: Navigation

Example

HTML
<focsd-header sticky collapse-below="640">
<strong slot="brand">Northwind</strong>
<focsd-nav-menu label="Main">
<focsd-nav-item href="#" current>Overview</focsd-nav-item>
<focsd-nav-item label="Products">
<a href="#">Analytics</a>
<a href="#">Reports</a>
</focsd-nav-item>
<focsd-nav-item href="#">Pricing</focsd-nav-item>
</focsd-nav-menu>
<focsd-button slot="actions" variant="action">Sign in</focsd-button>
</focsd-header>
<p style="padding: 1rem">Narrow the window below 640px to see the menu button.</p>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-header.js';
</script>
<focsd-header sticky collapse-below="640">…</focsd-header>

API

Attributes

AttributePropertyTypeDefault
stickystickybooleanfalse
collapse-belowcollapseBelownumber768
menu-labelmenuLabelstring—
compactcompactbooleanfalse

Methods

MethodDescription
closeMenu({ focus = false }, options)Close the compact navigation panel; optionally move focus back to the menu button.

Slots

SlotDescription
brandLogo or product name.
(default)Navigation, usually a focsd-nav-menu.
actionsButtons such as "Sign in".

CSS parts

Style the inside of the component with ::part(), for example focsd-header::part(header).

PartDescription
headerThe header element.
barThe row holding brand, menu button and actions.
brandThe brand container.
toggleThe menu button (compact only).
mainThe navigation container (a panel when compact).
actionsThe actions container.

Accessibility

  • A <header role="banner"> landmark: use one per page, at the top level (not inside <main>).
  • Below collapse-below pixels (default 768) a "Menu" button with aria-expanded and aria-controls shows and hides the navigation; slotted focsd-nav-menus switch to a vertical layout whose groups open in place.
  • Escape closes the menu and returns focus to the button; following a link closes it.
  • sticky keeps the header at the top while scrolling. Make sure focused elements are never hidden behind it (WCAG 2.4.11): add scroll-padding-top equal to its height.

Keyboard

KeyAction
Enter / Space (Menu)Open or close the navigation
EscapeClose and return focus to Menu