CSS Scroll Snap: scroll-snap-type and scroll-snap-align
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.
The old hack vs the modern fix
View demo// carousel.js + Slick/Swiper
import Swiper from 'swiper';
new Swiper('.carousel', {
slidesPerView: 1,
loop: true
});.carousel {
scroll-snap-type: x mandatory;
overflow-x: auto;
display: flex;
gap: 1rem;
}
.carousel > * {
scroll-snap-align: start;
}<!-- snap-x snap-mandatory on container, snap-start on items --><div class="flex gap-4 overflow-x-auto snap-x snap-mandatory"> <div class="snap-start shrink-0 w-80">Slide</div> <div class="snap-start shrink-0 w-80">Slide</div></div>Scroll snap browser support
Live demo
Why the modern way wins
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.