Sliding tab indicator

The active-tab underline slides and stretches to the newly selected tab instead of jumping.

ButtonPress Pure CSSVanilla JS time-based Targets: Web · App All modern browsers
Target
Implement the "Sliding tab indicator" effect in vanilla HTML/CSS/JS.

Context: The active-tab underline slides and stretches to the newly selected tab instead of jumping.
Trigger: the element is pressed (pointerdown → pointerup).
Timeline: time-based (duration + easing).

Motion tokens (normal):
- translateX (indicator): previous tab left → new tab left
- scaleX (indicator): previous tab width → new tab width
- duration: 280ms
- easing: cubic-bezier(0.2, 0.8, 0.2, 1)
- note: indicator is 1px wide at scaleX 1; width = scaleX × 1px, transform-origin left

Motion tokens (prefers-reduced-motion):
- translateX / scaleX: previous → new, instantly
- duration: 0ms

Technique: prefer pure CSS transitions/animations; use JS only to toggle classes; plain JavaScript (requestAnimationFrame / class toggles), no animation library required.

Acceptance:
- animate only transform and opacity unless the spec lists other properties
- no layout shift; content is visible without the animation
- when prefers-reduced-motion is set, use the reduced tokens only
- indicator is a single element moved by transform; tabs themselves never re-layout
- aria-selected drives the styling; arrow keys move selection

Generated from the spec. Prompts differ by target name only; the tokens are the source of truth.