StealThis .dev

Animated Tab Bar

A tab bar with a smooth sliding active indicator. Clicking tabs animates the indicator to the new position using CSS transitions driven by JS measurements.

Open in Lab
css vanilla-js css-transitions
Targets: JS HTML

Code

Animated Tab Bar

A tab navigation component with a sliding active indicator that smoothly follows the selected tab. The indicator position and width are driven by real DOM measurements, so it works with any tab label length.

How it works

  1. On click, JS reads the active tab’s offsetLeft and offsetWidth
  2. CSS custom properties --indicator-left and --indicator-width are updated on the tab bar element
  3. The indicator <span> transitions to the new position via transition: left 0.3s ease, width 0.3s ease
  4. Tab panels fade in with a short opacity transition

Variants

  • Swap border-bottom indicator for a filled background pill by changing the indicator CSS
  • Add overflow-x: auto to the tab list for scrollable tabs on mobile

When to use it

  • Settings pages
  • Dashboard sections
  • Content category filters