Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / More

SiteHeader

The top bar of a website that scrolls as a document: a skip link, the brand, the site navigation and actions. It sticks to the top of the window, and on narrow screens the navigation moves into a menu sheet.

Brand navigation and actions

When to useLink to "When to use"

  • Marketing and documentation sites built with Astro or React, where the window scrolls the whole page.

Use something else when:

  • you are building an app with a side navigation and its own scrolling content area: AppShell
  • you need the top of a page's content (title, description, actions): PageHeader

UsageLink to "Usage"

tsx
Copy
import { Button, SiteHeader, ThemeToggle } from "@arshad-shah/cynosure";

<SiteHeader
  brand="Acme"
  nav={[
    { label: "Docs", href: "/docs", current: true },
    { label: "Blog", href: "/blog" },
  ]}
  actions={<><ThemeToggle /><Button href="/sign-in">Sign in</Button></>}
/>
<main id="main">…</main>

In Astro, render it as a React island with client:load (or client:visible) so the menu button can open the sheet. Without hydration the bar, the links and the skip link still work; only the menu does not open.

Narrow screensLink to "Narrow screens"

Below collapseBelow (the header's own width: sm 40rem, md 48rem, lg 64rem) the links move into a sheet opened from a menu button. The actions stay in the bar.

Narrow menu with the keyboard

StickyLink to "Sticky"

By default the header stays at the top while the page scrolls, over a blurred view of the page. sticky={false} lets it scroll away.

Sticky while the page scrolls

PropsLink to "Props"

Every prop of SiteHeader
PropWhat it doesTypeDefault
brand
The logo or the site's name, at the inline start. Give a logo image its text alternative.ReactNode
brandHref
Where the brand links to. false shows the brand without a link. Default "/".string | false"/"
nav
The site navigation, as data. Each link is a real link; the current one is marked for assistive technology.SiteHeaderLink[]
actions
Controls at the inline end, such as a ThemeToggle, a search button or a sign-in Button. They stay in the bar.ReactNode
sticky
Keep the bar at the top of the window while the page scrolls, over a blurred view of the page. Default true.booleantrue
skipLink
Render a SkipLink before the bar, the first stop of the Tab order. Default true.booleantrue
skipTo
Where the skip link goes: # and the id of the page's main content. Default "#main".string"#main"
collapseBelow
Width of the header below which the navigation moves into a menu opened from a button: sm 40rem, md 48rem, lg 64rem. CSS only, so the right layout shows before any script runs. Default "md"."sm" | "md" | "lg""md"
size
Widest the bar's content gets: the size of its Container, to line up with the page. Default "lg"."sm" | "md" | "lg" | "full" | "xl""lg"
labels
Replace the built-in English text: the landmark name, the menu button, the menu title and the skip link.Partial<SiteHeaderLabels>
id
Set on the header element.string
className
Added to the header element, for layout.string
style
Layout only. Restyle through --cy-site-header-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
TabSkip link, brand, navigation links, actions, then the page
Enter on the skip linkFocus moves to the main content
Enter, Space, click on the menu buttonOpens the menu sheet; focus moves into it
EscapeCloses the sheet; focus returns to the menu button
Choosing a link in the sheetCloses the sheet; the browser follows the link
  • Landmarks: the header is the banner landmark at the top level of the page. The links are a list in a nav named "Main" (labels.nav), in the bar and in the sheet.
  • Current page: the item with current gets aria-current="page" and a highlight.
  • Skip link: a SkipLink to skipTo (#main) is rendered before the header. skipLink={false} leaves it out, for a page that has its own.
  • Menu button: an IconButton with aria-expanded. The sheet is a Sheet titled "Menu" (labels.menu), and its links are a SideNav.
  • No script needed for the layout: the switch to the menu is a container query, so a server-rendered page shows the right layout at once.
  • Right to left: the brand starts at the right.

TouchLink to "Touch"

The brand, the links and the menu button have hit areas of at least 24px, and 44px on coarse pointers. The links in the menu sheet are 44px tall.

ThemingLink to "Theming"

Theming, table 2
TokenWhat it setsDefault
--cy-site-header-heightLeast height of the bar--cy-control-height-lg plus twice --cy-space-5
--cy-site-header-backgroundBackground of the bar--cy-color-bg
--cy-site-header-borderHairline under the bar--cy-color-line
--cy-site-header-blurBlur of the page behind a sticky bar12px
--cy-site-header-link-colorNavigation links--cy-color-muted
--cy-site-header-link-current-colorCurrent and hovered link--cy-color-ink
--cy-site-header-link-highlightBackground of the current and hovered link--cy-color-soft
ts
Copy
createTheme({ components: { siteHeader: { blur: "0px", linkCurrentColor: "#c2410c" } } });

The breakpoints of collapseBelow are fixed, because a container query cannot read a token. className and style are for layout only.

SkipLink · SiteFooter · Section · Container · AppShell · ThemeToggle

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog