CSS & LayoutBaseline · Widely

CSS Scroll Snap

Mental Model

CSS Scroll Snap (scroll-snap-type on the container, scroll-snap-align on children) lets the Compositor Thread handle carousel and section snapping natively. It respects touch inertia and keyboard navigation without JS scroll timers fighting the user's finger.

Interactive Simulator

Mandatory vs Proximity Scroll Snap

Test how snap-type, snap-stop, and scroll-padding affect rest positions.

Parameter Profile
snapStrictnessmandatory
snapStopAlwaysOff
scrollPadding16
snapStrictness
mandatory
snapStopAlways
Off
scrollPadding
16
Parameters evaluated in real time.

Under the Hood

A JS carousel hijacks the wheel and fights momentum; CSS Scroll Snap lets the native physics engine predict where a fling will land and gently magnetizes it to the nearest snap line.

  1. Snap Area Registration: During Render Tree & Layout, each child's scroll-snap-align (start, center, end) registers a target coordinate.
  2. Strictness: mandatory always snaps to a target after scrolling stops; proximity snaps only when the rest point lands near a target.
  3. Padding Offset: scroll-padding-inline insets the snapport so sticky headers or peek gutters never overlap the snapped card.
CSS
.carousel {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 1rem;
}
.carousel > .slide {
  flex: 0 0 85%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

Works seamlessly with Dynamic Viewport Units and CSS Logical Properties.

Problem Genealogy

  • 2012–2018: Heavy JS carousel libraries reimplemented touch physics, breaking trackpad inertia, accessibility focus, and Ctrl+F scrolling.
  • 2019+: CSS Scroll Snap Level 1 unified snap behavior across Chromium, Gecko, and WebKit.

Production Pitfalls

Production Pitfall
  • Trapping tall content with mandatory: Using y mandatory on sections taller than the viewport prevents users from reading the bottom half of a section.
  • Skipping slides on fast swipes: Without scroll-snap-stop: always, a fast swipe jumps across multiple slides at once.
When Not to Use
  • When not to use scroll-snap-type: y mandatory: Never apply mandatory vertical snapping to long-form articles or variable-height pages; use proximity or omit it.

Connections & Logical Next Steps

CSS & LayoutCSS Scroll Snap
What This Unlocks
Leaf concept

Mechanical Comparisons