{"id":283236,"date":"2019-02-21T09:25:53","date_gmt":"2019-02-21T16:25:53","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=283236"},"modified":"2021-01-01T08:02:12","modified_gmt":"2021-01-01T16:02:12","slug":"scroll-snap-align","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/s\/scroll-snap-align\/","title":{"rendered":"scroll-snap-align"},"content":{"rendered":"\n
If you want an element to snap into place at the start of that element, give it a You can specify up to 2 values for this property, representing the block<\/em> and inline<\/em> axes, respectively. If you only give 1 value, that value will be used for both axes.<\/p>\n\n\nscroll-snap-align<\/code> is part of the CSS Scroll Snap Module. Scroll snapping refers to “locking” the position of the viewport to specific elements on the page as the window (or a scrollable container) is scrolled. Think of a scroll-snapping container like putting a magnet on top of an element that sticks to the top of the viewport and forces the page to stop scrolling right there.<\/p>\n\n\n\n
scroll-snap-align<\/code> is a required property for a scroll-snapping element within a scroll-snapping container. For more information on scroll-snapping containers see the
scroll-snap-type<\/code> almanac entry<\/a>.
scroll-snap-align<\/code> tells the browser which part of an element should be aligned when a snap point is encountered: Should the element snap to the
start<\/code>,
center<\/code> , or
end<\/code> of the parent container that contains the
scroll-snap-type<\/code> property?<\/p>\n\n\n\n\n\n\n\n
scroll-snap-align<\/code> value like so:<\/p>\n\n\n\n
\/* Assuming this element is a child of a container with `scroll-snap-type` set *\/\n.element {\n scroll-snap-align: start;\n}<\/code><\/pre>\n\n\n
Syntax<\/h3>\n\n\n
scroll-snap-align: [ none | start | end | center ]{1,2}<\/code><\/pre>\n\n\n\n
Values<\/h3>\n\n\n
scroll-snap-align<\/code> accepts the following values:<\/p>\n\n\n\n
none<\/code> disables scroll snapping on the element<\/li>
start<\/code> aligns the element’s start with the scroll container’s snapport when snapped into place<\/li>
end<\/code> aligns the element’s end with the scroll container’s snapport when snapped into place<\/li>
center<\/code> aligns the element’s center with the scroll container’s snapport when snapped into place<\/li><\/ul>\n\n\n
Example<\/h3>\n\n\n