StartFoundationsComponentsContent

Tab bar

A tab bar switches between sections of content in place, one section at a time.

Stable Figma
OverviewUsageAPIAccessibility
Overview Activity Members Billing
<tk-tab-bar label="Project" value="overview">
  <tk-tab value="overview">Overview</tk-tab>
  <tk-tab value="activity">Activity</tk-tab>
  <tk-tab value="members">Members</tk-tab>
  <tk-tab value="billing" disabled>Billing</tk-tab>
</tk-tab-bar>

Anatomy

Part What it is
tk-tab-bar the row of tabs on a full-width hairline; one Tab stop
tk-tab one tab, 40px tall
underline a 2px line under the selected tab
panel your own element, shown for the selected tab

Panels

The tab bar draws the tabs; the panels are your own elements. For each panel:

  • give the tab an id and a panel that names the panel's id;
  • give the panel role="tabpanel", aria-labelledby with the tab's id, and tabindex="0";
  • show the selected panel and hide the others when change fires.
<tk-tab-bar id="settings-tabs" label="Settings" value="profile">
  <tk-tab id="tab-profile" value="profile" panel="panel-profile">Profile</tk-tab>
  <tk-tab id="tab-alerts" value="alerts" panel="panel-alerts">Notifications</tk-tab>
</tk-tab-bar>
<div id="panel-profile" role="tabpanel" aria-labelledby="tab-profile" tabindex="0">Your name and photo</div>
<div id="panel-alerts" role="tabpanel" aria-labelledby="tab-alerts" tabindex="0" hidden>Email and push alerts</div>
<script>
  const tabs = document.getElementById('settings-tabs');
  tabs.addEventListener('change', () => {
    for (const tab of tabs.querySelectorAll('tk-tab'))
      document.getElementById(tab.panel).hidden = tab.value !== tabs.value;
  });
</script>

A router can swap the content instead. Either way, show the new panel at once: moving focus between tabs selects them.

Shape

shape="round" makes the hover and press tint behind each tab a pill. The underline stays the same.

This week This month This year
<tk-tab-bar label="Reports" value="week" shape="round">
  <tk-tab value="week">This week</tk-tab>
  <tk-tab value="month">This month</tk-tab>
  <tk-tab value="year">This year</tk-tab>
</tk-tab-bar>

States

Hover darkens a tab's label and tints it, press tints it the same, and keyboard focus shows a ring. The selected tab gets a dark label and the underline.

  • disabled on a tab: it's dimmed, can't be clicked, and the keyboard skips it. Say elsewhere why the section is unavailable.