Skip to main content

Basic

Tabs split one area into panels so only one is shown at a time. The list is role="tablist" with a name, every tab is role="tab" with aria-controls pointing to its role="tabpanel", and the panel points back with aria-labelledby. Only the selected tab is in the Tab order (tabindex); the arrow keys, Home and End move between tabs and select them. Use tabs for content that belongs together; use links when each item is a different page.

A compact wireless mouse with a quiet scroll wheel and a battery that lasts for months.

Appearance

Three ways to paint the same tabs: underline (the default, for a page or a card), pills (compact toolbars) and boxed (a segmented control). value selects a tab other than the first, as in the pills. The selected tab is told apart by colour, weight of the shape and the aria-selected state, never by colour alone. The list scrolls sideways when the tabs do not fit, so nothing wraps on a small screen.

Underline

The first panel.

Pills

The second panel.

Boxed

The first panel.

Icons and badges

An icon is decoration (aria-hidden) and the text stays, so the tab keeps its name. A badge is read after the name, for example “Messages 4”; when the number alone is unclear, add sr-only words such as “unread”.

Name, photo and contact details.

Vertical

For a list of sections, such as the settings of an account. The list sits at the start on wide screens and above the panel on narrow ones; aria-orientation="vertical" makes Up and Down the arrow keys.

Name of the store, language and time zone.

Options reference

Plain HTML and Tailwind classes; a small Alpine function keeps the selection and the keys.

Part Value Description
x-data="tabs('key')" function The wrapper. The argument is the key of the tab selected at first.
role="tablist" aria-label, aria-orientation Names the set. aria-orientation="vertical" only when the tabs are stacked.
role="tab" data-tab, aria-controls, aria-selected, tabindex One per panel. Alpine keeps aria-selected and tabindex in step with the selection.
role="tabpanel" aria-labelledby, tabindex="0", hidden The panel is a stop in the Tab order so a keyboard user can reach panels without focusable content.
Keys Left/Right or Up/Down, Home, End Move to the previous or next tab (wraps around), the first or the last, and select it.
Appearance underline, pills, boxed Only the classes of the list and of the tabs change.