What CSS Scroll Snap does
Scroll Snap lets a scroll container rest on defined snap points instead of stopping anywhere. It powers carousels, paginated galleries and full-screen sections with no JavaScript. The properties split cleanly: a few go on the scroll container to define the axis and strictness, and the rest go on each scrollable item to define where it aligns. This reference lists them all with their accepted values.
How it works
The container declares an axis and strictness with scroll-snap-type; each
child declares where it rests with scroll-snap-align:
.carousel {
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-padding-left: 1rem;
}
.carousel > .slide {
scroll-snap-align: start;
scroll-snap-stop: always;
scroll-margin-left: 0.5rem;
}
mandatory guarantees the scroll always lands on a slide; proximity only
snaps when you release near one. scroll-snap-align: start aligns each slide’s
left edge to the (padded) container edge. scroll-snap-stop: always blocks a
single fling from skipping past slides.
Tips and notes
- A snap container must actually scroll — set
overflowand a constrained size, or nothing snaps. - Combine
scroll-padding(container) withscroll-margin(item) to clear a sticky header. - Use logical-axis values
block/inlinefor writing-mode-aware snapping. scroll-snap-align: noneopts a single item out of snapping inside a snapping container.