CSS Reference ยท Scrolling, Interaction and UI
The scroll-snap-align property
Reference for the CSS scroll-snap-align property: choose which edge or center of a child snaps to the scroll container, with a live centered-card example.
The scroll-snap-align property is set on the children of a snap container. It says which part of the child lines up with the matching part of the container's snap area when snapping happens: its start edge, its center or its end edge.
Without it, a child contributes no snap position, so scroll-snap-type on the parent has nothing to snap to.
CSS
.card { scroll-snap-align: center; }
Try it
Syntax
CSS
scroll-snap-align: none | [ start | end | center ]{1,2};
- Initial value:
none - Applies to: all elements (they become snap areas)
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
none |
The element does not define a snap position. |
start |
The start edge of the element snaps to the start edge of the snap container. |
center |
The element's center snaps to the container's center. |
end |
The end edge snaps to the end edge of the container. |
| Two values | The first is for the block axis and the second for the inline axis. One value is used for both. |
Usage notes
- Use
centerfor galleries where a slide should sit in the middle. Add spacer space at the ends (as the demo does with pseudo-elements, or with padding) so the first and last items can actually reach the center. - Use
startfor full-width slides, and combine withscroll-paddingwhen a sticky header covers the edge. scroll-marginenlarges the snap area of an element, which shifts where it comes to rest.- Items that are larger than the scrollport can still be scrolled through; the browser does not force a snap in the middle of such an item.
- Do not set snap alignment on every tiny element, as too many snap points make scrolling feel sticky.
Browser support
Supported in every current major browser.
Related
scroll-snap-typeโ enables snapping on the containerscroll-snap-stopโ stops fast flicks skipping itemsscroll-marginโ outset for the snap area- Lesson: Scroll Snap