Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scroll-snap-align — alignment of snap positions

The scroll-snap-align property specifies how an element's snap area aligns inside its container when scrolling snaps. Set it on the target elements and set scroll-snap-type on the container.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

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

scroll-snap-align defines an element's snap positions relative to the container's snapping viewport (snapport). It does not enable snapping by itself: the container needs an appropriate scroll-snap-type. scroll-margin modifies the element's snap area, while scroll-padding reduces the snapport.

none defines no position in that axis; start, end, and center align the start, end, and center respectively. One value applies to both axes. Two values mean block axis followed by inline axis, not necessarily vertical followed by horizontal. The container's writing mode determines the axes. For an area larger than the snapport, the element's own writing mode determines the start and end directions.

The initial value is none; the property is not inherited, and animation is discrete. In the example, none start disables the block-axis position and defines an inline-start position. Horizontal scrolling should settle with a panel aligned to the left edge. Exact motion and panel selection depend on the browser; this property does not force a stop at every panel.

Examples

<!doctype html>
<meta charset="utf-8">
<title>scroll-snap-align</title>
<style>
  .scroller {
    width: 240px;
    height: 100px;
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    writing-mode: horizontal-tb;
    direction: ltr;
  }
  .item {
    flex: 0 0 240px;
    scroll-snap-align: none start;
    display: grid;
    place-items: center;
    background: #def;
  }
  .item:nth-child(2) { background: #fed; }
</style>
<div class="scroller" tabindex="0" aria-label="Scroll snap demo">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>

Result

Initially, panel 1 is visible. After horizontal scrolling settles, a panel's left edge aligns with the container's left edge. Expected settled scrollLeft values: 0, 240, or 480 CSS pixels.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources