Principles Foundation Accessibility Design System Guidelines Deutsch Français Italiano English Our design principles User-centred Recognisable Inclusive Reduced Holistic Self-explanatory Task-oriented Appropriate SBB Brand portal Logo Digital clock Rights of use Base colors Additional colors Off brand colors Icons Timetable icons Pictograms About accessibility Über diesen Guide Contact Further information Product Owner User Research Interaction Design Visual Design Development Content Design Testing What is a design system? Designing Coding FAQ Help Process Contribution Contact Overview Base Components Overview Releases Design Tokens Components Overview Base Informations Overview Base Components Overview App Icons Power-Apps Digital banner ads SAP Design Guidelines AI Design: Basics Header Info

What does the component do?

The header is the top section of a website or application that contains important navigation elements to make it easier for users to access the main areas of the site or application.

When should the component be used?

  • On every page of a website to ensure consistent navigation and brand presence.
  • To make main navigation elements, logo, search functions and important links visible and easily accessible.
  • To improve usability and orientation on the website.

Rules

  • Navigation elements should be logically grouped and labelled for easy navigation. They always have an icon (to the left of the label).
  • If a hamburger menu is placed, it is always displayed first and to the left.
  • The header should contain a search function if the website offers a lot of content.
  • Avoid too many elements in the header so that clarity and responsive behaviour are not negatively affected.
HeaderButton HeaderLink
Anatomy

Anatomy of the component


Number Type Description Optional Info
1 Component sbb-header-button oder sbb-header-link No
1a Component sbb-icon No
1b Text Label Yes
1c Component sbb-menu Yes
2 Component sbb-logo Yes
Demo Basic
Expanded
Size S
With User Menu
Basic Scroll Hide
Expanded Scroll Hide
Container Scroll Origin Scroll Hide
Copy HTML to clipboard.
Implementation

The sbb-header component is a container for actions and a logo, and it is displayed at the top of the page.

Slots

The slot can contain:

Slotted elements are aligned to the left. Use <div class="sbb-header-spacer"> to align elements after it to the right.

<sbb-header>
  <sbb-header-link icon-name="hamburger-menu-small" href="https://sbb.ch/somewhere">
    Menu
  </sbb-header-link>
  <sbb-header-button icon-name="magnifying-glass-small">Search</sbb-header-button>
  <div class="sbb-header-spacer"></div>
  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-logo protective-room="none"></sbb-logo>
  </a>
</sbb-header>

Style

Setting the expanded property will cause the sbb-header component to take up the full width of the page.

To avoid that tabbed/focused elements get hidden behind the header,
it's recommended to set on the <html> tag the CSS property scroll-padding-top to var(--sbb-header-height) or to a greater value.
With this, it's ensured that content will be visible all the time.

The component has two sizes, named m (default) and s.
For the latter, the usage of the sbb-signet with protective-room='panel' is suggested.

<sbb-header size="s">
  <sbb-header-link icon-name="hamburger-menu-small" href="https://sbb.ch/somewhere">
    Menu
  </sbb-header-link>
  <sbb-header-button icon-name="magnifying-glass-small">Search</sbb-header-button>
  <div class="sbb-header-spacer"></div>
  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-signet protective-room="panel"></sbb-signet>
  </a>
</sbb-header>

Active state

To indicate an active state of the sbb-header-link or sbb-header-button,
the CSS class sbb-active should be set on the corresponding element.

From accessibility perspective accessibility-current="page" (or aria-current="page" for buttons)
should be set whenever the CSS class sbb-active is set.

<sbb-header size="s">
  <sbb-header-link
    icon-name="magnifying-glass-small"
    href="https://sbb.ch/somewhere"
    class="sbb-active"
    accessibility-current="page"
  >
    Overview
  </sbb-header-link>
  <div class="sbb-header-spacer"></div>
  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-signet protective-room="panel"></sbb-signet>
  </a>
</sbb-header>

Positioning and visibility

By default, the sbb-header has a fixed position at the top of the page;
when the page is scrolled down, a box-shadow appears below it and the component remains visible.
It's possible to change this behavior by setting the hideOnScroll property to true, or adding the hide-on-scroll
attribute: in this case, the box-shadow is still set, but the component disappears when the page is scrolled down and
then reappears as soon as it's scrolled up. It's also possible to bind this behaviour to something other than the document,
using the scrollOrigin property, which accepts an HTMLElement or the id of the element to search for.

<sbb-header expanded hideOnScroll>
  <sbb-header-button icon-name="magnifying-glass-small">Search</sbb-header-button>
  <div class="sbb-header-spacer"></div>
  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-logo protective-room="none"></sbb-logo>
  </a>
</sbb-header>

Customizing

Users can customize position and behaviour of actions inside the sbb-header component
by adding classes to sbb-header-button/sbb-header-link elements and then defining their own style rules.

All the examples in Storybook have the following requirements:

  1. four action items (with custom icons);
  2. the first item is always left aligned and has expand-from set to small;
  3. the other three items are left aligned in breakpoints zero to large, and right aligned from large to ultra;
  4. the last item is not visible in breakpoints zero to small;
  5. the logo is always aligned to the right.

To achieve the alignment requirements, two div tags with a CSS class named sbb-header-spacer were added:

  • one after the first sbb-header-button item (that will be hidden on smaller screen sizes);
  • the second, before the logo. Since this spacer will only be shown on small screen sizes, we need a new class to target it (in this example sbb-header-spacer-logo);

We also need a class (in this example last-element) on the last sbb-header-button to achieve requirement n° 4.

Finally, the following custom CSS has been added(*).

The result can also be seen in the home and home-logged-in stories.

.last-element,
.sbb-header-spacer-logo {
  display: none;
}

@media screen and (width >= 600px) {
  .last-element {
    display: block;
  }
}

@media screen and (width < 1024px) {
  .sbb-header-spacer {
    display: none;
  }

  .sbb-header-spacer-logo {
    display: block;
  }
}
<sbb-header>
  <sbb-header-button icon-name="..." expand-from="small"> ... </sbb-header-button>

  <!-- Will be hidden on small screen sizes -->
  <div class="sbb-header-spacer"></div>

  <sbb-header-button icon-name="..."> ... </sbb-header-button>
  <sbb-header-button icon-name="..."> ... </sbb-header-button>
  <sbb-header-button icon-name="..." class="last-element"> ... </sbb-header-button>

  <!-- Will only be shown on small screen sizes -->
  <div class="sbb-header-spacer sbb-header-spacer-logo"></div>

  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-logo protective-room="none"></sbb-logo>
  </a>
</sbb-header>

The sbb-header can be also customized by adding the application's name and version:
a helper class named sbb-header-info is provided to achieve the correct visual result.

<sbb-header size="s">
  <sbb-header-link icon-name="hamburger-menu-small" href="https://sbb.ch/somewhere">
    Menu
  </sbb-header-link>

  <span class="sbb-header-info">
    <strong>Application name</strong>
    <span>V. 1.1</span>
  </span>

  <div class="sbb-header-spacer"></div>

  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-signet protective-room="panel"></sbb-signet>
  </a>
</sbb-header>

Content overflow

If a certain sbb-header-button/sbb-header-link should be shrunken (receive ellipsis) when there is too little space,
set the CSS class sbb-header-shrinkable on the desired sbb-header-button/sbb-header-link.

<sbb-header>
  <sbb-header-link icon-name="hamburger-menu-small" href="https://sbb.ch/somewhere" target="_blank">
    Menu
  </sbb-header-link>
  <sbb-header-button class="sbb-header-shrinkable">
    Christina Müller has a long name
  </sbb-header-button>
  <div class="sbb-header-spacer"></div>
  <a aria-label="Homepage" href="/" class="sbb-header-logo">
    <sbb-logo protective-room="none"></sbb-logo>
  </a>
</sbb-header>

(*) Technical note: Due the presence of media-query rules, it was not possible to add those rules directly
in the component's stories (see also this Storybook issue),
so they were wrapped into a style tag and added to the Storybook's configuration file named preview-head.html.

Properties

Name Attribute Privacy Type Default Description
expanded expanded public boolean false Whether to allow the header content to stretch to full width. By default, the content has the appropriate page size.
hideOnScroll hide-on-scroll public boolean false Whether the header should hide and show on scroll.
scrollOrigin scroll-origin public HTMLElement | null null The element's id or the element on which the scroll listener is attached. For attribute usage, provide an id reference.
size size public 'm' | 's' 'm' / 's' (lean) Size of the header, either m or s.

CSS Properties

Name Default Description
--sbb-header-height zero-small:var(--sbb-spacing-fixed-14x);large-ultra:var(--sbb-spacing-fixed-24x) Can be used to modify height of the header.
--sbb-header-z-index 10 Can be used to modify the z-index of the header.

Slots

Name Description
Use the unnamed slot to add actions, content and logo to the header.