DEV3 Technologies home

Scroll-snap testimonial carousel

A swipeable testimonial carousel built on native CSS scroll snapping, with optional previous and next buttons and no slider library.

Tailwind CSSCardscarouseltestimonialsscroll-snapresponsive

Live preview

Code

How it works

What it solves

Most carousel plugins ship kilobytes of JavaScript to do something the browser already does: scroll horizontally and stop on item boundaries. This version relies on CSS scroll snapping, so swipe, trackpad and keyboard scrolling all work with momentum and no layout thrash.

How it works

The ul is a flex row with overflow-x-auto and snap-x snap-mandatory; each card declares snap-center and shrink-0, so the scroll position always settles with one card centered. On phones a card is 85% wide, which leaves a visible sliver of the next one as a swipe hint; from the sm breakpoint it is a fixed w-80. The tiny script only powers the arrow buttons: it measures the first card plus the 16px gap and calls scrollBy, so the step stays correct if you change the card width. Hiding the scrollbar uses an arbitrary property class.

Adapting it

  • Change the card width classes to show two or more cards at once on desktop.
  • Generate the li items from your reviews collection in a loop.
  • Remove the script and buttons entirely if swiping is enough for your audience.

Pitfalls

  • The track has tabindex="0" so keyboard users can scroll it; keep a visible focus outline.
  • Do not hide the scrollbar without offering the buttons, or mouse users may not discover more cards.
  • scroll-smooth should respect prefers-reduced-motion; add motion-reduce:scroll-auto if needed.

How to use it

  1. Drop the section into any page that loads Tailwind CSS 4.
  2. Loop your testimonial records into the li elements, keeping the same classes.
  3. Keep the id track or update the script selector if you rename it.
  4. For several carousels on one page, query by a class and scope each button pair to its section.

Licence: DEV3 Snippet Licence. Free to use, change and ship in personal and commercial projects. Attribution is appreciated, not required. Please do not redistribute snippets as a collection.

Related snippets