StealThis .dev

Swipe Tabs

Horizontally swipeable tab panels with a sliding indicator. Supports touch swipe gestures and tap navigation. No libraries.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Swipe Tabs

Tab navigation where panels can be swiped horizontally on touch devices. The tab indicator slides to follow the active tab, and swipe velocity determines whether the panel snaps to the next tab or springs back.

How it works

  1. Tab buttons update the active tab and animate the sliding underline indicator
  2. touchstart / touchmove / touchend track horizontal swipe delta
  3. Panels are laid out horizontally in a flex track; translateX shifts the visible panel
  4. If swipe delta exceeds 25% of container width, the tab advances or retreats

Performance

  • Uses will-change: transform on the track for GPU compositing
  • touch-action: pan-y allows native vertical scroll to work alongside horizontal swipe

When to use it

  • Mobile feeds with multiple content categories (Feed, Trending, Following)
  • Settings pages with grouped sections
  • Any layout that needs a lightweight, swipeable tab bar