Layout Intermediate

Scroll snapping without a carousel library

Carousels used to mean Slick, Swiper, or custom scroll math. CSS scroll snap gives you card-by-card or full-width snapping with a few properties.

6 lines
1.carousel {
2  scroll-snap-type: x mandatory;
3  overflow-x: auto;
4  display: flex; gap: 1rem;
5}
6.carousel > * { scroll-snap-align: start; }
Old 12+ lines
1// carousel.js + Slick/Swiper
2import Swiper from 'swiper';
3new Swiper('.carousel', {
4  slidesPerView: 1.2,
5  spaceBetween: 16,
6  scrollbar: { el: '.swiper-scrollbar' },
7  touchEventsTarget: 'container'
8});
Widely available Since 2020 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2020.

69+
68+
11+
79+
Interop 2026 focus area ? Learn more β†’
scroll horizontally to snap
Slide 1
Slide 2
Slide 3
Slide 4
Slide 5
Slide 6
scroll-snap-type: x mandatory
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more
⚑

No library

No Slick, Swiper, or custom scroll math. Just CSS on a scroll container.

✦

Native touch

Touch and trackpad scrolling work out of the box. No touchstart handlers.

∞

Accessible

Real overflow scroll, so keyboard and screen readers get normal scroll behavior.

Lines Saved
12+ β†’ 6
No JS dependency
Old Approach
JS carousel lib
Slick, Swiper, touch handlers
Modern Approach
scroll-snap CSS
Native snapping

How it works

Carousels were usually built with a JS library that handled scroll position, touch events, and snap calculations. You paid in bundle size and maintenance.

scroll-snap-type: x mandatory on a scroll container plus scroll-snap-align: start (or center) on each item gives you snapping. Use overflow-x: auto and flex/grid for the layout. No JS.

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC