Header / top bar
The top bar of an app or site: brand, navigation and actions. Collapses to a menu button on small screens.
Example
<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>import { Header } from '@focsd-dev/react';
export function Example() { return <Header sticky collapse-below="640">…</Header>;}<script setup>import '@focsd-dev/components/focsd-header.js';</script>
<template> <focsd-header sticky collapse-below="640">…</focsd-header></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-header.js';
// template<focsd-header sticky collapse-below="640">…</focsd-header><script> import '@focsd-dev/components/focsd-header.js';</script>
<focsd-header sticky collapse-below="640">…</focsd-header>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
sticky | sticky | boolean | false |
collapse-below | collapseBelow | number | 768 |
menu-label | menuLabel | string | — |
compact | compact | boolean | false |
Methods
| Method | Description |
|---|---|
closeMenu({ focus = false }, options) | Close the compact navigation panel; optionally move focus back to the menu button. |
Slots
| Slot | Description |
|---|---|
brand | Logo or product name. |
(default) | Navigation, usually a focsd-nav-menu. |
actions | Buttons such as "Sign in". |
CSS parts
Style the inside of the component with ::part(), for example focsd-header::part(header).
| Part | Description |
|---|---|
header | The header element. |
bar | The row holding brand, menu button and actions. |
brand | The brand container. |
toggle | The menu button (compact only). |
main | The navigation container (a panel when compact). |
actions | The actions container. |
Accessibility
- A
<header role="banner">landmark: use one per page, at the top level (not inside<main>). - Below
collapse-belowpixels (default 768) a "Menu" button witharia-expandedandaria-controlsshows and hides the navigation; slottedfocsd-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.
stickykeeps the header at the top while scrolling. Make sure focused elements are never hidden behind it (WCAG 2.4.11): addscroll-padding-topequal to its height.
Keyboard
| Key | Action |
|---|---|
| Enter / Space (Menu) | Open or close the navigation |
| Escape | Close and return focus to Menu |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.