CSS scroll-snap-align Property

The CSS scroll-snap-align property specifies how an element aligns within a scroll container when scrolling snaps to that element.

It defines the snap position along the block and inline axes using the values none, start, end, or center. Common uses include image galleries, horizontal carousels, full-screen sections, and other interfaces where scrolling should settle at predictable positions.

scroll-snap-align Syntax

The scroll-snap-align property accepts one or two alignment keywords.

Basic Syntax

selector {
  scroll-snap-align: start;
}

Available Values

.item {
  scroll-snap-align: none;
}
.item {
  scroll-snap-align: start;
}
.item {
  scroll-snap-align: end;
}
.item {
  scroll-snap-align: center;
}

Two-Value Syntax

.item {
  scroll-snap-align: start center;
}
.item {
  scroll-snap-align: center end;
}
.item {
  scroll-snap-align: none start;
}
.item {
  scroll-snap-align: end end;
}

When two values are provided, the first controls alignment along the block axis and the second controls alignment along the inline axis.

CSS-Wide Keywords

.item {
  scroll-snap-align: initial;
}
.item {
  scroll-snap-align: inherit;
}
.item {
  scroll-snap-align: unset;
}
.item {
  scroll-snap-align: revert;
}
.item {
  scroll-snap-align: revert-layer;
}

Lengths, percentages, and numerical offsets are not accepted. Use scroll padding or scroll margin when additional alignment spacing is needed.

Property Values

Value Description
none Does not define a snap position for the element along the specified axis.
start Aligns the start edge of the element's scroll snap area with the start edge of the scroll container's snapport.
end Aligns the end edge of the element's scroll snap area with the end edge of the snapport.
center Aligns the center of the element's scroll snap area with the center of the snapport.
initial Resets the property to its initial value of none.
inherit Uses the computed value from the parent element.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to All elements
Computed value Two keywords, one for each axis
Animation type Discrete
Percentages Not applicable
Values none, start, end, center
Number of values One or two
Related container property scroll-snap-type

Valid Values

.item {
  scroll-snap-align: start;
}
.item {
  scroll-snap-align: center;
}
.item {
  scroll-snap-align: end;
}
.item {
  scroll-snap-align: start center;
}
.item {
  scroll-snap-align: none end;
}

Invalid Values

.item {
  scroll-snap-align: 20px;
}
.item {
  scroll-snap-align: 50%;
}
.item {
  scroll-snap-align: left;
}
.item {
  scroll-snap-align: mandatory;
}
.item {
  scroll-snap-align: start center end;
}

The property accepts only the four alignment keywords, with a maximum of two values.

How It Works

CSS Scroll Snap allows a scroll container to settle at defined positions after scrolling. The container controls whether snapping is enabled, while its descendants identify where snapping can occur.

The scroll-snap-align property establishes a snap position by aligning a target's scroll snap area with the container's snapport.

The Scroll Container

.container {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

The container enables mandatory snapping along the physical horizontal axis.

The Scroll Targets

.container .item {
  flex: 0 0 250px;
  scroll-snap-align: start;
}

Each item defines a start-aligned snap position.

The Snapport

The snapport is the region used to align scroll targets. By default, it corresponds to the scrollport, but scroll-padding can adjust its boundaries.

The Scroll Snap Area

An element's scroll snap area is based on its transformed border box and can be expanded or contracted using scroll-margin.

Selecting a Snap Position

When scrolling ends, the browser selects an appropriate snap position according to the container's snap settings, available snap targets, scroll direction, and scrolling operation.

The exact target selection is browser-controlled. Setting scroll-snap-align does not guarantee that every scrolling action will stop at a particular element.

No Layout Changes

The property does not change an element's dimensions, margins, padding, or normal position in the document. It defines alignment positions for scrolling.

Start Alignment

The start value aligns the start edge of a target's scroll snap area with the corresponding start edge of the snapport.

Horizontal Start Alignment

.carousel {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.carousel .slide {
  flex: 0 0 250px;
  scroll-snap-align: start;
}

In left-to-right horizontal writing, slides snap toward the left edge of the container.

Vertical Start Alignment

.sections {
  height: 400px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.sections .section {
  min-height: 300px;
  scroll-snap-align: start;
}

In horizontal writing, sections snap toward the top edge.

Adding Start Spacing

.carousel {
  scroll-padding-inline-start: 30px;
}
.carousel .slide {
  scroll-snap-align: start;
}

The slides align inward from the logical inline-start edge, allowing consistent spacing at the start of the visible scrolling region.

Important Consideration

The meaning of start follows the relevant logical axis. It does not always correspond to the physical left or top edge.

Center Alignment

The center value aligns the center of a target's scroll snap area with the center of the snapport along the snapping axis.

Centered Horizontal Carousel

.carousel {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.carousel .slide {
  flex: 0 0 220px;
  scroll-snap-align: center;
}

Slides snap toward the horizontal center of the visible scrolling region.

Centered Vertical Sections

.scroll-container {
  height: 400px;
  overflow-y: auto;
  scroll-snap-type: y proximity;
}
.scroll-container .section {
  min-height: 200px;
  scroll-snap-align: center;
}

When the browser chooses to snap, a section can align near the vertical center of the snapport.

Centered Alignment With Scroll Padding

.carousel {
  scroll-padding-inline: 40px;
}
.carousel .slide {
  scroll-snap-align: center;
}

Equal start and end scroll padding reduces the snapport's inline dimension while keeping its center unchanged.

Unequal Scroll Padding

.carousel {
  scroll-padding-left: 20px;
  scroll-padding-right: 80px;
}

Unequal insets shift the center of the snapport. Center-aligned targets therefore align relative to the adjusted region rather than the geometric center of the full scrollport.

Important Consideration

Targets near the beginning or end of the content may not reach the center unless sufficient scroll range is available.

End Alignment

The end value aligns the end edge of a target's scroll snap area with the corresponding end edge of the snapport.

Horizontal End Alignment

.carousel {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.carousel .slide {
  flex: 0 0 250px;
  scroll-snap-align: end;
}

In left-to-right horizontal writing, slides snap toward the right edge.

Vertical End Alignment

.scroll-container {
  height: 350px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.scroll-container .section {
  min-height: 220px;
  scroll-snap-align: end;
}

In horizontal writing, sections snap toward the bottom edge.

Adding End Spacing

.carousel {
  scroll-padding-inline-end: 50px;
}
.carousel .slide {
  scroll-snap-align: end;
}

The end-aligned slides can stop inward from the logical inline-end edge.

Important Consideration

End alignment follows the writing direction. In right-to-left horizontal writing, inline-end corresponds to the physical left edge.

Two-Value Syntax

Two values allow different alignment settings for the block and inline axes.

Block and Inline Order

.item {
  scroll-snap-align: start center;
}

The first value, start, applies to the block axis. The second value, center, applies to the inline axis.

Different Alignment on Each Axis

.item {
  scroll-snap-align: end start;
}

The element uses end alignment on the block axis and start alignment on the inline axis.

Disabling Alignment on One Axis

.item {
  scroll-snap-align: none center;
}

The element does not define a snap position on the block axis but can snap to the center along the inline axis.

One Value Applies to Both Axes

.item {
  scroll-snap-align: center;
}

This is equivalent to:

.item {
  scroll-snap-align: center center;
}

Two-Dimensional Scrolling

.grid-scroll {
  width: 400px;
  height: 300px;
  overflow: auto;
  scroll-snap-type: both mandatory;
}
.grid-scroll .cell {
  scroll-snap-align: start center;
}

In horizontal writing, cells define top alignment on the block axis and centered alignment on the inline axis.

Important Consideration

The two-value order is always block axis first, inline axis second. It does not change to horizontal first or vertical first when the writing mode changes.

Using scroll-snap-type

The scroll-snap-type property is applied to the scroll container and controls whether snapping occurs, along which axis, and with what strictness.

Mandatory Snapping

.container {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.container .item {
  scroll-snap-align: start;
}

The browser must snap to an appropriate position when snapping is applicable.

Proximity Snapping

.container {
  overflow-x: auto;
  scroll-snap-type: x proximity;
}
.container .item {
  scroll-snap-align: center;
}

The browser may snap when a suitable position is sufficiently close. The proximity threshold is determined by the browser.

Vertical Snapping

.container {
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.container .item {
  scroll-snap-align: start;
}

Logical Axis Snapping

.container {
  overflow-x: auto;
  scroll-snap-type: inline mandatory;
}
.container .item {
  scroll-snap-align: start;
}

The inline keyword selects the logical inline axis rather than a fixed physical axis.

Both Axes

.container {
  overflow: auto;
  scroll-snap-type: both mandatory;
}
.container .item {
  scroll-snap-align: center;
}

Disabling Snapping

.container {
  scroll-snap-type: none;
}

With snapping disabled, the scroll-snap-align values do not cause the container to snap.

Choosing Mandatory or Proximity

Mandatory snapping is useful when each item represents a distinct scrolling position. Proximity snapping offers more freedom when users need to stop between targets.

Be cautious with mandatory snapping when content is taller or wider than the snapport. Users must still be able to reach and read all content.

Scroll Padding and Scroll Margin

Scroll padding and scroll margin modify the regions used by scroll-snap-align.

Property Applied To Purpose
scroll-snap-align Snap target Defines the target's snap alignment.
scroll-padding Scroll container Adjusts the snapport used for alignment.
scroll-margin Snap target Adjusts the target's scroll snap area.

Container-Side Scroll Padding

.carousel {
  scroll-padding-inline-start: 40px;
}
.carousel .slide {
  scroll-snap-align: start;
}

Slides can snap inward from the logical inline-start edge of the scrollport.

Target-Side Scroll Margin

.carousel .featured {
  scroll-margin-inline-start: 20px;
  scroll-snap-align: start;
}

The featured slide receives additional alignment spacing at its inline-start edge.

Combining Both Properties

.carousel {
  scroll-padding-inline-start: 40px;
}
.carousel .featured {
  scroll-margin-inline-start: 20px;
  scroll-snap-align: start;
}

For inline-start alignment, the combined settings can place the featured slide's border edge approximately 60 pixels inward from the corresponding scrollport edge.

Using Scroll Padding With Center Alignment

.carousel {
  scroll-padding-inline: 30px;
}
.carousel .slide {
  scroll-snap-align: center;
}

Center alignment uses the adjusted snapport rather than the full scrollport.

Important Consideration

Neither scroll padding nor scroll margin creates scroll snapping independently. They modify alignment when a scrolling operation uses the snap positions.

Writing Modes and Text Direction

The start and end values use logical directions. Their physical meaning depends on the writing mode and text direction.

Horizontal Left-to-Right Writing

.container {
  writing-mode: horizontal-tb;
  direction: ltr;
}
.container .item {
  scroll-snap-align: start;
}

For horizontal scrolling, inline-start corresponds to the left edge. For vertical scrolling, block-start corresponds to the top edge.

Horizontal Right-to-Left Writing

.container {
  writing-mode: horizontal-tb;
  direction: rtl;
}
.container .item {
  scroll-snap-align: start;
}

For horizontal scrolling, inline-start corresponds to the right edge.

Vertical Writing

.container {
  writing-mode: vertical-rl;
}
.container .item {
  scroll-snap-align: start;
}

In vertical-rl, block-start corresponds to the right edge. Inline-start corresponds to the top or bottom edge depending on text direction.

Logical Alignment Reference

Writing Mode Direction Block-Start Inline-Start
horizontal-tb ltr Top Left
horizontal-tb rtl Top Right
vertical-rl ltr Right Top
vertical-rl rtl Right Bottom
vertical-lr ltr Left Top
vertical-lr rtl Left Bottom

Choosing Logical or Physical Scroll Axes

The container's scroll-snap-type can use physical axes (x and y) or logical axes (block and inline). The alignment values remain logical in either case.

Important Consideration

Use logical scroll padding and margin properties when alignment spacing should adapt automatically to writing mode and text direction.

Practical Examples

Image Gallery

.image-gallery {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.image-gallery img {
  flex: 0 0 280px;
  width: 280px;
  height: 200px;
  object-fit: cover;
  scroll-snap-align: center;
}

Each image can snap to the center of the gallery.

Horizontal Navigation Cards

.card-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 20px;
}
.card-list .card {
  flex: 0 0 200px;
  scroll-snap-align: start;
}

Cards can snap near the inline-start edge while still allowing flexible scrolling between positions.

Full-Screen Sections

.page-sections {
  height: 100vh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.page-sections section {
  min-height: 100vh;
  scroll-snap-align: start;
}

Sections can snap to the top of the scroll container. Use caution when content exceeds the available viewport height.

Product Carousel

.product-carousel {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.product-carousel .product {
  flex: 0 0 240px;
  scroll-snap-align: center;
}

Product cards can settle at centered snap positions.

Two-Dimensional Grid

.grid-container {
  width: 400px;
  height: 300px;
  overflow: auto;
  scroll-snap-type: both proximity;
}
.grid-container .grid-item {
  scroll-snap-align: start center;
}

Grid items define different alignment positions along the block and inline axes.

Disabling Snap Alignment for Selected Items

.carousel .item {
  scroll-snap-align: start;
}
.carousel .decorative-item {
  scroll-snap-align: none;
}

Decorative items do not establish their own snap positions, although they remain part of the scrolling content.

scroll-snap-align Example

This interactive example compares start, center, and end alignment in horizontal scroll containers. Use the buttons to bring the highlighted target into view, or scroll each panel manually to observe snapping.

HTML Example

<div class="snap-align-demo">
  <div class="snap-example start">
    <h3>Start Alignment</h3>
    <div class="snap-panel">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item target">Target</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>
    <button type="button">Align Target</button>
  </div>
  <div class="snap-example center">
    <h3>Center Alignment</h3>
    <div class="snap-panel">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item target">Target</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>
    <button type="button">Align Target</button>
  </div>
  <div class="snap-example end">
    <h3>End Alignment</h3>
    <div class="snap-panel">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item target">Target</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
    </div>
    <button type="button">Align Target</button>
  </div>
</div>

CSS Example

.snap-align-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 20px;
}
.snap-align-demo .snap-panel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  scroll-snap-type: x mandatory;
}
.snap-align-demo .item {
  flex: 0 0 90px;
  padding: 25px 10px;
  text-align: center;
  background-color: #e2e8f0;
}
.snap-align-demo .target {
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.snap-align-demo .start .item {
  scroll-snap-align: start;
}
.snap-align-demo .center .item {
  scroll-snap-align: center;
}
.snap-align-demo .end .item {
  scroll-snap-align: end;
}
.snap-align-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

JavaScript Example

document.querySelectorAll(".snap-align-demo .snap-example").forEach((example) => {
  const button = example.querySelector("button");
  const target = example.querySelector(".target");
  const alignment = example.classList.contains("center") ? "center" : example.classList.contains("end") ? "end" : "start";
  button.addEventListener("click", () => {
    target.scrollIntoView({
      behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth",
      inline: alignment,
      block: "nearest"
    });
  });
});
Browser Result

Start Alignment

1
2
Target
4
5
6

Center Alignment

1
2
Target
4
5
6

End Alignment

1
2
Target
4
5
6

Click each button to align the highlighted target. In left-to-right horizontal writing, start positions the target toward the left, center positions it in the middle, and end positions it toward the right.

Changing to Proximity Snapping

.snap-align-demo .snap-panel {
  scroll-snap-type: x proximity;
}

With proximity snapping, the browser may allow scrolling to stop between snap positions when a target is not sufficiently close.

Disabling Snap Alignment

.snap-align-demo .item {
  scroll-snap-align: none;
}

The items no longer establish snap positions through this property.

Browser Compatibility Note

The exact final alignment depends on available scroll range, target dimensions, and browser snapping behavior. Edge items may not reach every requested position.

Accessibility Considerations

Scroll snapping can make navigation more predictable, but overly restrictive snapping can interfere with reading and keyboard navigation.

Avoid Trapping Content

Do not create mandatory snap layouts that prevent users from reaching content between snap positions. Pay particular attention to sections larger than the snapport.

Maintain Keyboard Accessibility

Ensure interactive controls within scrolling content can be reached using the keyboard and have visible focus indicators.

Respect Reduced Motion Preferences

Scroll snapping does not require smooth animation. When smooth scrolling is added, provide a reduced-motion alternative.

Avoid Unexpected Movement

Do not use scripted snapping that repeatedly overrides the user's intended scrolling position.

Provide Clear Navigation Controls

For carousels, provide appropriately labeled previous and next controls when they improve usability. Do not rely exclusively on touch gestures.

Test Zoom and Text Scaling

Ensure content remains reachable when users increase browser zoom or text size, particularly when mandatory snapping is enabled.

Consider Proximity Snapping

Use proximity instead of mandatory when flexible stopping positions are important for reading or interaction.

Common Mistakes

Applying scroll-snap-align Only to the Container

.container {
  scroll-snap-align: start;
}

This does not define snap positions for the container's children. Apply the property to the intended snap targets.

Forgetting scroll-snap-type

.item {
  scroll-snap-align: center;
}

Without an appropriate snapping container, this declaration does not enable scroll snapping.

Using Unsupported Values

.item {
  scroll-snap-align: left;
}

Use start, end, center, or none.

Using Lengths as Alignment Values

.item {
  scroll-snap-align: 20px;
}

Use scroll padding or scroll margin to create alignment offsets.

Reversing Two-Value Order

The first value controls the block axis and the second controls the inline axis. The order does not depend on which axis scrolls horizontally.

Assuming Start Always Means Left

Start alignment follows the logical direction of the relevant axis and may correspond to another physical edge.

Using Mandatory Snapping With Oversized Content

Mandatory snapping can make intermediate content difficult to reach when sections are larger than the snapport.

Ignoring Scroll Range

Targets near the beginning or end of a scroll container may not reach their requested snap alignment.

Expecting Scroll Snapping Without Overflow

A container must have a usable scrolling area for its scroll snap behavior to become apparent.

Confusing Alignment With Snap Strictness

scroll-snap-align defines where targets align. scroll-snap-type controls whether snapping is mandatory, proximity-based, or disabled.

Important Considerations

Keep the following points in mind when using scroll-snap-align:

  • It defines scroll snap positions for individual elements.
  • Its initial value is none, and it is not inherited.
  • It accepts none, start, end, and center.
  • It accepts one or two alignment values.
  • A single value applies to both the block and inline axes.
  • With two values, the block-axis value comes first and the inline-axis value comes second.
  • It does not accept lengths, percentages, or numerical offsets.
  • It does not enable scroll snapping by itself.
  • The scroll container uses scroll-snap-type to control snapping behavior.
  • Alignment is based on the target's scroll snap area and the container's snapport.
  • scroll-padding adjusts the snapport.
  • scroll-margin adjusts an individual target's scroll snap area.
  • Start and end alignment follow logical writing directions.
  • Center alignment uses the center of the snapport, which may be affected by scroll padding.
  • Available scroll range can limit the final alignment.
  • Browser algorithms determine which snap position is selected.
  • Mandatory snapping should not prevent users from reaching content.
  • Test scrolling behavior with keyboard, mouse, touch, and different viewport sizes.

Browser Support

The CSS scroll-snap-align property is widely supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Older browsers may have limited support or use earlier scroll snapping implementations. Snap target selection and scrolling behavior can also vary between browsers.

For current compatibility information, visit Can I Use? and search for scroll-snap-align.

When unsupported, content generally remains scrollable, but the requested snap alignment may not be applied.

Specifications

The scroll-snap-align property is defined in CSS Scroll Snap Module Level 1.

CSS Scroll Snap Module Level 1

The specification defines scroll snap alignment positions and how target snap areas align with a scroll container's snapport.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-snap-align