scroll-snap-align

Specifies which edge an element snaps by in a scrolling container.

Initial value
none
Inherited
No
Animatable
no
Applies to
all elements (children of a scroll container)
JavaScript
element.style.scrollSnapAlign = "center"
On this page

Example

#
CSS
.sections {
  height: 100dvh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}

.sections > section {
  scroll-snap-align: start;
}
Preview

Definition and usage

#

The scroll-snap-align property is set on the children of a container with scroll-snap-type. It decides whether, after scrolling, the element aligns its start, centre, or end to the container’s edge.

start suits lists and sections read from the top, center suits photo carousels, and end suits rarer cases such as a chat scrolled from the bottom.

You can change the gap between the container’s edge and the snap point with the scroll-padding property on the container.

Syntax

#
Syntax
scroll-snap-align: none | start | center | end;

Values

#
  • start

    Scroll: the card aligns to the left edge.
  • center

    Scroll: the card aligns to the centre.
  • end

    Scroll: the card aligns to the right edge.

Values in practice

#

start

Scroll: the card aligns to the left edge.
.item { scroll-snap-align: start; }

center

Scroll: the card aligns to the centre.
.item { scroll-snap-align: center; }

end

Scroll: the card aligns to the right edge.
.item { scroll-snap-align: end; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Combine scroll-snap-align with scroll-padding on the container if a header covers the top of a snapped section.
  • Full-screen section snapping can be tiring on long pages. Use it sparingly.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.