Skip to content

Tabs

Switches between related views within the same context. It exposes the selected value—each tab declares its own (data-ts-value), and the matching panel is shown. It has variants and a vertical orientation (orientation-vertical).

Navigation · TaishoDS Core, in plain HTML.

Examples

One working example per case. Each example is the HTML of its preview—copy it as is, and with Core’s CSS and JS loaded, it looks and works the same.

Tabs with three panels

This month’s sales compared with last month.
Recent account activity.
Notification preferences.
html

Class reference

Every value of each modifier, with its HTML ready to copy.

Variant

Tab style: default (underline) or secondary (pills).

This month’s sales.
Recent activity.
This month’s sales.
Recent activity.
html

Orientation

horizontal (row) or vertical (side column).

This month’s sales.
Recent activity.
This month’s sales.
Recent activity.
html

States

is-active marks the open tab; disabled disables it.

This month’s sales.
Recent activity.
This month’s sales.
Recent activity.
html

Combinations

Variant and orientation combined.

This month’s sales.
Recent activity.
html

When to use

  • They’re alternate views of the same object, like details, activity, and settings.
  • Only one makes sense at a time, and switching is cheap.
  • Users don’t need to compare two views at the same time.

When not to use

  • It’s a form value, not a view → segmented-control.
  • They’re separate pages with their own URL → nav-bar or sidebar.
  • The content is best read in full, top to bottom → accordion or plain sections.

Do

  • Short labels that say what’s inside.
  • Few tabs. If they don’t fit on one line, this isn’t the right component.

Don’t

  • Don’t hide something the user always needs to see in a tab.
  • Don’t use them for the steps of a process. Steps have an order; tabs don’t.

TaishoDS Core

Needs Core’s JS, which hooks in through data-ts-* attributes.

Core switches the active panel. The markup already includes role="tab".

Core hooks into it through these attributes. They go in the markup, and there’s nothing to initialize.

  • data-ts-tabs
  • data-ts-tabs-panel
  • data-ts-tabs-tab
  • data-ts-value

What it does: Switches the active panel and keeps aria-selected and tabindex in sync. The ← and → arrow keys move between tabs (APG pattern).

From the CDN, without a build, load taisho.tabs.css along with taisho.base.css. Also load:

  • taisho.badge.css

For how Core works in general, see Behavior.

Accessibility

Implements the Tabs pattern from the WAI-ARIA APG.

  • role="tablist" / role="tab" / role="tabpanel" pattern with aria-selected and aria-orientation.
  • Each tab carries an id and aria-controls pointing to its panel. Each panel carries aria-labelledby pointing to its tab, so a screen reader announces it with the tab’s name. Pairing comes from data-ts-value.
  • Core generates any missing id on init and keeps the ones already written, along with aria-controls, aria-labelledby, and tabindex. A tab without a panel gets no aria-controls, so it never points at nothing.
  • The panel is a Tab stop (tabindex="0"), so content without focusable elements is still reachable by keyboard. Inactive panels carry hidden.
  • Roving tabindex: the active tab is the only one in the Tab order. The arrow keys of the tablist’s axis switch tabs and selection follows focus. disabled tabs are skipped.
  • When the tab changes, the indicator slides to the new one with a transform transition. Under prefers-reduced-motion: reduce it jumps without animating.

Keyboard

On top of what the browser already does (Tab moves focus, Enter activates a button).

Key What it does
→←In a horizontal tablist (orientation-horizontal) they switch to the next and previous tab, wrapping around. On an RTL page they swap: ← moves forward and → moves back. In the vertical tablist they do nothing.
↓↑In a vertical tablist (orientation-vertical, which exposes aria-orientation="vertical") they switch to the next and previous tab. In the horizontal one they do nothing and the page keeps scrolling.
Home/EndFirst and last enabled tab.
TabLeaves the tablist. The active tab is the only tab stop, and the next one is the panel (tabindex="0").

Verification

What was actually tested. Anything that wasn’t tested says so—we’d rather say “not verified” than claim too much.

  • axe WCAG 2.2 A + AA in a real browser, in light and dark mode, before every release.
  • keyboard Key map documented above, checked against the component.
  • screen reader Not verified with a screen reader. Test it in your own combination of components, not just here, where each one appears alone and on its happy path.