CSS Portal

CSS scroll-snap-type 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-type property controls whether and how a scroll container will "snap" to certain positions as the user scrolls. It declares that the scrolling viewport should consider the snap positions defined by its children and attempt to land on one of those positions when scrolling finishes, whether the scroll was initiated by touch, mouse wheel, keyboard, or script. In effect, it turns ordinary continuous scrolling into a series of discrete stop points that help users land precisely on content islands like slides, cards, or full-page sections.

Snapping behavior is a cooperation between the container and its children: the container declares that snapping should happen and the children define where the snap points are via scroll-snap-align. The container’s scrollable area, including any inset that should be respected when aligning snap positions, can be adjusted with scroll-padding, and it only takes effect when the element is actually scrollable (which is controlled by overflow). Because snapping uses those child-defined alignment anchors and the container’s padding, you can design layouts where items align to edges, centers, or create custom offsets for the resting position.

From a user-experience and input perspective, snap behavior affects the end-of-scroll settling: it can shorten or extend the final animation after a fling, and it can influence keyboard or programmatic scrolling by guiding where focus lands. That makes snapping valuable for predictable navigation patterns like carousels, page-by-page sections, or step-through previews, but it also means designers must be careful not to interfere with expected scrolling behavior - for example, avoid trapping users in a snap loop or making it harder to reach off-center content. Consider how snapping interacts with inertia on touch devices and with precise wheel or trackpad scrolling so the result feels natural rather than jarring.

In practice, use snapping where clear, repeatable stops improve comprehension and interaction: image galleries, onboarding flows, and paginated content are common places. Avoid overusing it on long, free-form lists where users expect to scan continuously. Test with variable-sized children, different input devices, and assistive technologies; provide alternate navigation controls (buttons, keyboard shortcuts) when snapping is used for essential navigation. Also be mindful of animation performance and layout complexity, since frequent layout adjustments during scroll can have a cost on lower-powered devices.

Definition

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

Interactive Demo

1
2
3
Scroll »

Syntax

scroll-snap-type: none | [ x | y | block | inline | both ] [ mandatory | proximity ]? 

Values

  • noneWhen the visual viewport of this scroll container is scrolled, it must ignore snap points.
  • xThe scroll container snaps to snap positions in its horizontal axis only.
  • yThe scroll container snaps to snap positions in its vertical axis only.
  • blockThe scroll container snaps to snap positions in its block axis only.
  • inlineThe scroll container snaps to snap positions in its inline axis only.
  • bothThe scroll container snaps to snap positions in both of its axes independently (potentially snapping to different elements in each axis).
  • mandatoryThe visual viewport of this scroll container must snap to a snap position if it isn't currently scrolled.
  • proximityThe visual viewport of this scroll container may snap to a snap position if it isn't currently scrolled. The user agent decides if it snaps or not based on scroll parameters. This is the default snap strictness if any snap axis is specified.

Example

<div class="example">
<h2>Horizontal Scroll Snap</h2>
<div class="snap-container" tabindex="0">
<article class="card">Item 1</article>
<article class="card">Item 2</article>
<article class="card">Item 3</article>
<article class="card">Item 4</article>
<article class="card">Item 5</article>
<article class="card">Item 6</article>
<article class="card">Item 7</article>
<article class="card">Item 8</article>
</div>
</div>
/* Basic page styles */
.example {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  padding: 24px;
  max-width: 100%;
  box-sizing: border-box;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  color: #111827;
}

/* Scroll snap container */
.snap-container {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 12px 0;
  scroll-snap-type: x mandatory; /* key property */
  scroll-padding: 24px; /* optional: padding for snap alignment */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Individual snap items */
.card {
  flex: 0 0 320px; /* fixed width items */
  height: 180px;
  background: linear-gradient(135deg, #6EE7B7 0%, #3B82F6 100%);
  color: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  scroll-snap-align: start; /* align each item to the start of the container */
  box-shadow: 0 8px 20px rgba(2,6,23,0.12);
}

/* Optional: hide scrollbar in WebKit browsers */
.snap-container::-webkit-scrollbar {
  height: 8px;
}

.snap-container::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.12);
  border-radius: 999px;
}

Browser Support

The following information will show you the current browser support for the CSS scroll-snap-type 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!