Skip to content
IndexRequest a UIAboutContact

Tabs with Sliding Indicator

Tabs with an indicator that slides and resizes to the active tab, in underline or pill style, with arrow-key navigation.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean UI mockup of a tab bar with four tabs Overview, Activity, Billing and Team, the active tab Activity with dark text and a thin dark underline indicator, a faint trail showing the indicator sliding from Overview, below it a content panel with a heading and two lines of text, a second variant with a dark rounded pill behind the active tab with white text, light theme, flat modern style. Negative: heavy shadows, clutter, text errors. Reduced motion: static design.

About this pattern

Definition

A moving indicator connects the old and new tab, which helps people see what changed. It is a single element positioned with transform and width taken from the active tab's measurements. The tablist must stay accessible: roving tabindex, arrow keys, Home and End, and panels tied to tabs with aria-controls.

Purpose & UX principles

  • Measure the active tab with offsetLeft and offsetWidth, then set the indicator's translateX and width.
  • Use role tablist, tab and tabpanel with aria-selected and aria-controls.
  • Left and Right arrows move between tabs; automatic activation is fine for light panels.
  • Update the indicator again on resize.

Interaction states

  • Click or use the arrow keys; choose the underline or pill style.

Motion specification

  • The indicator slides in 250ms.
  • Reduced motion: it jumps.

Responsive behaviour

  • Do not hide inactive panels from the document with only opacity; use hidden.
  • Keep the animation under 250 ms.

Code

HTML
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Style"><button data-p="0" aria-pressed="true">Underline</button><button data-p="1" aria-pressed="false">Pill</button></div><div class="tl" id="tl" role="tablist" aria-label="Account"><i class="ind" id="ind"></i><button role="tab" id="t0" aria-selected="true" aria-controls="p0" tabindex="0">Overview</button><button role="tab" id="t1" aria-selected="false" aria-controls="p1" tabindex="-1">Activity</button><button role="tab" id="t2" aria-selected="false" aria-controls="p2" tabindex="-1">Billing</button><button role="tab" id="t3" aria-selected="false" aria-controls="p3" tabindex="-1">Team</button></div><div class="pn" id="pn"><section role="tabpanel" id="p0" aria-labelledby="t0"><b>Overview</b><p>A summary of your account.</p></section><section role="tabpanel" id="p1" aria-labelledby="t1" hidden><b>Activity</b><p>Recent sign-ins and changes.</p></section><section role="tabpanel" id="p2" aria-labelledby="t2" hidden><b>Billing</b><p>Invoices and payment methods.</p></section><section role="tabpanel" id="p3" aria-labelledby="t3" hidden><b>Team</b><p>Members and their roles.</p></section></div></div>

Related patterns

Tab Navigation

↗
Tab NavigationNavigation

Segmented Control

↗
Segmented ControlInputs & Forms

Scrollable Tab Bar

↗
Scrollable Tab BarNavigation