UI Components Easy
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.
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
- On click, JS reads the active tab’s
offsetLeftandoffsetWidth - CSS custom properties
--indicator-leftand--indicator-widthare updated on the tab bar element - The indicator
<span>transitions to the new position viatransition: left 0.3s ease, width 0.3s ease - Tab panels fade in with a short opacity transition
Variants
- Swap
border-bottomindicator for a filledbackgroundpill by changing the indicator CSS - Add
overflow-x: autoto the tab list for scrollable tabs on mobile
When to use it
- Settings pages
- Dashboard sections
- Content category filters