Components · Navigation

Tabs

Tabs organise content across screens, data sets and interactions at the same level of hierarchy. A tab bar lets the user move between groups of related content without leaving the page. For content that must be read in order, use steps instead.

How to add a tab bar to a page. The files are components/css/tabs.css and components/js/tabs.js.

Basic Usage

Link the shared files once per page. Never copy the rules into a page.

StepWhat to do
1. Link<link rel="stylesheet" href="/components/css/tabs.css"> and <script src="/components/js/tabs.js"></script> (the sliding line, for content tabs and link tabs). Both templates already have them.
2. ChooseContent tabs switch panels on the same page: role="tablist" with button.tab. Navigation tabs go to another page: a nav.tab-bar with a.tab.
3. Type and sizetab-bar--primary or tab-bar--secondary; Large is the default, add tab-bar--md or tab-bar--sm.
4. IconsThe icon class ms (Material Symbols) comes from the page, as in the templates.

Tabs


API

Classes

ClassUse
tab-barThe bar. Needs tab-bar--primary or tab-bar--secondary.
tab-bar--md, tab-bar--smMedium and Small. Default is Large.
tab-bar--on-greyFor grey surfaces.
tab, tab--active, tab--icon-onlyA tab. tab--active, aria-selected="true" and aria-current all give the active look.
tab__icon, tab__label, tab__dot, tab__countParts of a tab.
tab-panelThe content of a content tab.

Things to know

  • Always a button (content tabs) or an a (navigation tabs). Never a div with a click handler.
  • Keep exactly one active tab.
  • Breakpoint: values switch at 769px; 640–768px is still mobile.
  • Set --tab-line-active on the bar for the accent colour. Never restyle .tab::after or .tab-bar__indicator.
  • Keep the same aria-label on a navigation bar on every page, so the line can slide across the page change.
  • A bar with tab-bar--page navigates one page: a.tab links to #section-id, any number of sections. It is sticky; set --tab-sticky-top when a fixed header sits above it. data-tabs-hash="off" keeps the address from changing.
  • The My Pages account menu is migrated: nav.tab-bar.tab-bar--primary of a.tab, with --tab-line-active: var(--brand).

CSS / Tailwind

The component is one CSS file and one script, shared by every page. Link them, never copy them.

CSS (components/css/tabs.css)
JS (components/js/tabs.js)