Preview brand Custom

Header

The frame at the top of every page: the logo, the main menu, search and the settings menu. You're looking at it: scroll to see it shrink, and open the settings button to change theme.

There is no boxed example on this page: the header above is the real one. These docs are pages for looking things up, so theirs has no call to action. The checks below are run on this site's Insights page, where the header has every part.

js
// somnia.config.mjs
nav: [
  { href: '/services/', label: 'Services' },
  { href: '/case-studies/', label: 'Case studies' },
  { href: '/insights/', label: 'Insights' },
  { href: '/about/', label: 'About' },
],
cta: { href: '/contact/', label: 'Start a project' },
features: { search: true, themeMenu: true },

When to use it

  • Every page of every site has it, from the page layout. A page doesn't add it or leave it out.
  • What goes in it is the site's choice, in its config: the menu's links, one call to action, search, the settings menu.

Use something else when:

  • The page sits inside a section and needs to say where: a breadcrumb above its heading. The main menu already marks the section.
  • A site is not launched yet: its holding page has a plain bar with the logo alone.
  • The links are for the foot of the page (legal pages, social accounts): the footer.
  • Sticky and translucent: the page's own colour at 94% with a blur, so content passes underneath without showing through the menu.
  • The main menu marks the section you are in, on the section's own page and on every page inside it.
  • Shrinks on scroll: its padding tightens and a logo's strapline folds away, on one slightly bouncy easing (easing.bounce) so it reads as one movement. What the logo does as it shrinks is the brand's own.
  • Search: a box in the header on wide screens, a Search link between 800 and 1100 px, and a round Search link on phones. See Search.
  • Settings menu: a button opens Appearance (Light, Dark, or Auto, which follows the device) and, where a site has more than one, Theme. The choice is remembered on that device. Its icon, style and shape are the site's choice (Site settings in Somnia CMS).
  • On a phone (below 800 px) the links and the call to action move into a menu behind a button whose three lines turn into a cross. On a site with search, the Search link stands beside it and the settings are at the end of the open menu.
  • Skip link: the first thing a keyboard reaches, jumping straight to the page's content.
  • Steady on short pages: the space the header gives up as it shrinks is kept below it, so a page only a little taller than the window can't shrink and grow the header in a loop.
  • Over the hero (client sites): with headerOverlay in a site's config ('on', or 'try' to offer it on Site style) and overlayHeader on a page, the header sits clear over a full-width picture or video, light on dark with a soft shade behind it so it always reads, and turns solid once the page scrolls or a menu opens.
  • An app (Somnia CMS) can have a second menu beside settings for its account; only one of the header's menus is open at a time.

Do and don't

Do

  • Keep the menu to the site's main sections: four or five links
  • Give it one call to action, the thing the site most wants
  • Name a section the same in the menu, its page heading and its breadcrumbs

Don't

  • Put a second row or a drop-down of sub-pages in it
  • Add links that leave the site
  • Hide the menu behind the three-line button on wide screens

The footer has a page of its own.

Accessibility

What it does for you

  • A skip link is the first thing the keyboard reaches, and goes to the page’s content.
  • The main menu is a navigation landmark named "Main". The section you are in is marked for screen readers and underlined as well as coloured.
  • The settings button says whether its menu is open. The menu takes the focus when it opens; the arrow keys, Home and End move through it; Escape closes it and goes back to the button; moving on with Tab closes it.
  • On a phone the menu button is named "Open menu" or "Close menu" and says whether the menu is open. Escape closes it and goes back to the button.
  • It sticks to the top of the window, and a link you tab to is never left underneath it: the page scrolls until it shows.
  • With reduced motion it changes size at once, and the menu button’s lines become a cross at once.
  • The settings and menu buttons are 38px square.

What you need to do

  • Menu words that match each section’s own heading.
  • A logo with a name: the brand’s logo link says the site’s name and "home".
  • One call to action whose words say what happens.

Keyboard

KeyWhat it does
TabThe skip link, the logo, the menu’s links, search, the call to action, then the settings button.
EnterOn the skip link: goes to the page’s content.
Enter, Space or DownOn the settings button: opens its menu on the first choice.
Down, Up, Home, EndMove through the open menu; Down and Up go round.
EscapeCloses the settings menu or the phone menu, and goes back to its button.

What a screen reader is told

  • A banner, with a navigation named "Main".
  • The link for the section you are in: "current page", or "current" on a page inside it.
  • The settings button: its name ("Display settings"), collapsed or expanded. Its menu: Light, Dark and Auto as radio items, one of them checked.
  • The phone menu button: "Open menu", collapsed; "Close menu", expanded.

This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.

WCAG 2.2

CriterionLevelHow this meets it
1.4.1 Use of ColorAThe current section is underlined as well as coloured.
2.1.1 KeyboardAEvery part works from the keyboard, the menus’ arrow keys included.
2.1.2 No Keyboard TrapATab leaves each menu and Escape closes it.
2.3.3 Animation from InteractionsAAAThe shrinking and the menu button’s change switch off with reduced motion.
2.4.1 Bypass BlocksAThe skip link.
2.4.3 Focus OrderAFocus goes into an opened menu and back to its button when it closes.
2.4.7 Focus VisibleAAThe usual 2px ring.
2.4.11 Focus Not Obscured (Minimum)AAA link that takes the focus is scrolled clear of the header (scroll-padding-top).
2.5.8 Target Size (Minimum)AAButtons are 38px square.
3.2.3 Consistent NavigationAAThe same menu, in the same order, on every page.
4.1.2 Name, Role, ValueAButtons say whether their menus are open; the menu’s choices say which is checked.

The criteria this component has a part in. A page that uses it still has to meet the rest.

Checked

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
14 of 14 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 7 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot yet
Not yet checked by a person

The 14 checks made with the keyboard, on the example at the top of this page:

  • Passed The first Tab lands on "Skip to content", and Enter takes the keyboard into the page’s content
  • Passed The menu is a navigation landmark named "Main", and marks the section you are in
  • Passed Tab goes through the logo, the menu, search, the call to action and the settings button, in that order
  • Passed Enter on the settings button opens its menu, says so, and puts the focus on the first choice
  • Passed Down, Up, Home and End move through the menu, and Down and Up go round
  • Passed Enter on a choice makes it, and the menu says which is checked
  • Passed Escape closes the menu and puts the focus back on its button
  • Passed Tabbing on past the menu closes it
  • Passed A link reached with Tab or Shift+Tab is never left under the header
  • Passed On a phone the menu button says "Open menu", then "Close menu", and whether the menu is open
  • Passed In the open phone menu, Tab goes through its links, the call to action and the settings
  • Passed Escape closes the phone menu and puts the focus back on its button
  • Passed The settings and menu buttons are at least 24px square
  • Passed With reduced motion the header and the menu button change at once

Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.

Not yet checked

  • How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
  • Windows high contrast (forced colours) has not been looked at by a person.
  • On a phone the settings sit at the end of the open menu as a group, their choices still menu radio items with no menu round them. How a screen reader reads that has not been checked.
  • The header at 400% zoom has not been looked at by a person.
  • The header over a hero (Headland) is checked for contrast by eye only: the shade behind it is drawn over whatever picture or video the site chose.

Evidence

Where it's used

WhereFor
Every page of every Somnia sitemediadreams.co.uk, Headland Yachting (over the hero on its home page) and the starter.
Somnia CMSWith two menus: how the page looks, and the account.

What we saw, and what changed

WhenWhat we sawWhat changed
At high zoom the header wraps, and the settings menu hung off the edge of the screen.The menu is moved to stay inside the window (1.5.0).
The menu did not show which section a page was in.It marks the section, on its own page and on every page inside it (1.7.0).
On a page only a little taller than the window, the header shrank and grew in a loop.The room it gives up as it shrinks is kept below it (1.22.0).
On a phone, search was inside the menu and the settings button stood in the header.Search stands in the header, and the settings are at the end of the open menu (1.68.0).
A page title passing under the header read through it where a browser draws no blur.The header is more solid: 94% of the page colour, up from 86% (1.74.0).
Writing this page’s checks. In the settings menu, Escape left the focus at the top of the page, the arrow keys did nothing, and tabbing past it left it open. The menu’s landmark had no name. The menu button’s lines still moved with reduced motion.All five fixed (1.83.0).

From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.

What it rests on

What we don't know yet

  • Which menu links are followed, and how often the phone menu is opened, is not counted.
  • Whether people find the settings button, and know what it is from its icon, has not been tested.