A carousel is one of the most-requested UI components โ and you don't need Swiper or a framework for the basics. It's one flex row and a translateX. Here's a live one with arrows, dots, autoplay, and swipe, in vanilla JS.
๐ Try it (drag/swipe, dots, autoplay): https://dev48v.infy.uk/design/day18-carousel.html
The core trick
Put all slides in one flex row (.track), each width: 100%. To show slide N, set track.style.transform = translateX(-N * 100%) with a CSS transition. That's the whole carousel.
Then layer on the features
- Arrows / dots: change the index, re-apply the transform, sync the active dot.
-
Wrap-around:
(index + 1) % countand(index - 1 + count) % count. -
Autoplay: a
setIntervalthat advances; clear it on hover, restart on leave. -
Swipe: on
pointerdownrecord X and disable the transition; onpointermovedrag the track; onpointerupsnap to the nearest slide if you dragged past ~20%.
When to reach for a library
Hand-rolled is great for learning and simple cases. For virtualized, accessible, touch-perfect carousels, use Embla or Swiper โ but now you know what they're doing.
๐จ Full build (track โ goTo() โ arrows โ dots โ autoplay โ swipe) on the page: https://dev48v.infy.uk/design/day18-carousel.html
Part of DesignFromZero. ๐ https://dev48v.infy.uk
United States
NORTH AMERICA
Related News
Secret Claude Tracker Shocks Users After Anthropic's Anti-Surveillance Stance
12h ago
EV Batteries Defy Expectations, Last Hundreds of Thousands of Miles
1d ago
GBase 8a Performance Anomaly Case Study: How a Single Parameter Change Sparked a Chain Reaction
1d ago
Who Else Has Inherited a Codebase With Zero Comments and a Prayer?
1d ago
ๅฎ็พ็ๅนณๅบธ
3h ago