CSS Portal

CSS scroll-snap-align Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The scroll-snap-align property tells the browser which point on an element should be lined up with the scroll container’s snapport when a snapping action occurs. It is applied to the snap candidates (typically the children of a scroll container) and does not change the element’s layout or positioning — it only defines how the element should be aligned relative to the container when the container settles on a snap position. Because it targets the snap point of an element rather than altering flow, you can use it on static, relatively positioned, or transformed elements without affecting their normal placement until a snap happens.

For snapping to work, the container must have snapping turned on; the container’s snapping behavior and axis/strength determine how and when elements with scroll-snap-align are considered. If multiple candidates are close to the snapport at the end of a scroll, the user agent chooses which one to snap to based on proximity and the container’s configured snapping rules. You can control how the container behaves and which axes are involved via scroll-snap-type, and you can affect the effective snap area by using scroll-padding on the container or adjusting each item’s snap offset with scroll-margin on the items themselves.

Practically, scroll-snap-align is often used to create carousels, full-page sections, or horizontally paged lists where each item should come into a predictable position after a flick or programmatic scroll. It works with logical axes, so it respects writing-mode and direction; an alignment that looks like “start” or “end” will map to the appropriate physical edge in vertical writing modes or right-to-left contexts. It also cooperates with scroll behavior settings — for example, programmatic scrolling that requests smooth scrolling will still snap according to the defined snap alignment and the container’s behavior (scroll-behavior).

When designing with this property, it’s usually best to set snap alignment on the direct children you intend to be candidates, keep the alignments consistent for uniform paging, and adjust container padding or item margins to fine-tune visual spacing. Remember that snapping is a final-step adjustment to the scrolling position: it won’t prevent intermediate scrolling positions or change how touch momentum is handled, but it will determine the target position where the scroller comes to rest.

Definition

Initial value
none
Applies to
all elements
Inherited
no
Computed value
as specified
Animatable
yes
JavaScript syntax
object.style.scrollSnapAlign

Interactive Demo

1
2
3
Scroll »

Syntax

scroll-snap-align: [ none | start | end | center ]{1,2}

Values

  • noneThe box does not define a snap position in that axis.
  • startThe start alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis.
  • endThe end alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis.
  • centerThe center alignment of this box's scroll snap area, within the scroll container's snapport is a snap position in this axis.

Example

<div class='viewport'>
<h2>Scroll Snap - scroll-snap-align example</h2>
<div class='carousel' tabindex='0'>
<div class='card snap-start'>Item 1 - start</div>
<div class='card snap-center'>Item 2 - center</div>
<div class='card snap-end'>Item 3 - end</div>
<div class='card snap-start'>Item 4 - start</div>
<div class='card snap-center'>Item 5 - center</div>
</div>
</div>
/* Basic reset */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  margin: 24px;
  background: #f7f7fb;
  color: #111;
}

.viewport {
  max-width: 900px;
  margin: 0 auto;
}

h2 {
  font-size: 1.125rem;
  margin: 0 0 12px 12px;
  color: #333;
}

.carousel {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.card {
  flex: 0 0 70%;
  height: 200px;
  border-radius: 12px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.125rem;
  /* default alignment (can be overridden by specific classes) */
  scroll-snap-align: start;
  box-shadow: 0 6px 18px rgba(18,22,45,0.08);
}

/* Demonstrate different scroll-snap-align values */
.snap-start { scroll-snap-align: start; }
.snap-center { scroll-snap-align: center; }
.snap-end   { scroll-snap-align: end; }

/* Simple visual styling */
.card:nth-child(1) { background: linear-gradient(135deg,#6c5ce7,#a29bfe); }
.card:nth-child(2) { background: linear-gradient(135deg,#00b894,#55efc4); color: #072; }
.card:nth-child(3) { background: linear-gradient(135deg,#fd79a8,#ff7675); }
.card:nth-child(4) { background: linear-gradient(135deg,#00bcd4,#26c6da); }
.card:nth-child(5) { background: linear-gradient(135deg,#ffb86b,#ff7b54); }

/* Focus styles for keyboard users */
.carousel:focus {
  outline: 3px solid rgba(99,102,241,0.12);
  outline-offset: 6px;
}

Browser Support

The following information will show you the current browser support for the CSS scroll-snap-align property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!