Skip to content
IndexRequest a UIAboutContact

Tab Navigation

Accessible tabs with a sliding underline that switch between related panels.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build an accessible tab component with three tabs (Overview, Specs, Reviews) following the WAI-ARIA tabs pattern: a container with role="tablist", buttons with role="tab", aria-selected, aria-controls and a roving tabindex (selected tab tabindex 0, others -1), and panels with role="tabpanel", aria-labelledby and hidden when inactive. Left and Right arrows move focus and selection, Home and End jump to the ends. An absolutely positioned underline (2px, accent colour) slides to the selected tab by animating transform and width over 280ms cubic-bezier(0.4,0,0.2,1); recompute its position on resize. Panels fade in with a 6px upward slide in 160ms. Make the tab list horizontally scrollable if it overflows and scroll the selected tab into view. Disable animations for prefers-reduced-motion.

About this pattern

Definition

A row of labels where exactly one is selected and shows its panel below. An underline slides from tab to tab to show the change. It implements the WAI-ARIA tabs pattern.

Purpose & UX principles

  • Lets people switch between peer views of the same context without leaving the page.
  • Do not use tabs for steps in a process or for navigation between unrelated pages.
  • Keep labels short, one or two words, and avoid more than six tabs.

Interaction states

  • Default, hover and selected, with aria-selected reflecting the active tab.
  • Only the selected tab is in the tab order; arrows move between tabs (roving tabindex).
  • Panels not shown have the hidden attribute.

Motion specification

  • Underline: width and translateX, 280ms cubic-bezier(0.4, 0, 0.2, 1).
  • Panel: 160ms fade and 6px upward slide.
  • Reduced motion: underline jumps, panel appears without animation.

Responsive behaviour

  • If tabs overflow, make the list horizontally scrollable with the active tab scrolled into view.
  • Never wrap the labels onto two lines.

Code

HTML
<div class="tabs">
  <div class="list" role="tablist" aria-label="Product" id="list">
    <button role="tab" id="t1" aria-controls="p1" aria-selected="true">Overview</button>
    <button role="tab" id="t2" aria-controls="p2" aria-selected="false" tabindex="-1">Specs</button>
    <button role="tab" id="t3" aria-controls="p3" aria-selected="false" tabindex="-1">Reviews</button>
    <span class="bar" id="bar" aria-hidden="true"></span>
  </div>
  <div role="tabpanel" id="p1" aria-labelledby="t1" class="panel"><h3>Overview</h3><p>A short description of what the product does and who it is for.</p></div>
  <div role="tabpanel" id="p2" aria-labelledby="t2" class="panel" hidden><h3>Specs</h3><p>Weight 240 g · Battery 36 h · Water resistance IP67.</p></div>
  <div role="tabpanel" id="p3" aria-labelledby="t3" class="panel" hidden><h3>Reviews</h3><p>4.7 out of 5 from 1,284 reviews.</p></div>
</div>

Related patterns

Bottom Navigation

↗
Bottom NavigationNavigation

Top Navigation

↗
Top NavigationNavigation

Breadcrumb

↗
BreadcrumbNavigation