CSS Scroll Snap Generator

Start from a preset
Live preview
CSS

          
Controls
Browser support

What scroll-snap-type does

Scroll snap makes a scroll container settle on defined positions rather than wherever the momentum happens to stop. It turns an ordinary overflow container into a carousel with no JavaScript, keeping native scrolling, keyboard support and momentum intact.

Syntax

scroll-snap-type: <axis> <strictness>; scroll-snap-align: <position>;
PartWhat it controls
scroll-snap-typeGoes on the scroll container. x mandatory snaps horizontally and always lands on a snap point; proximity only snaps when the scroll stops nearby.
scroll-snap-alignGoes on each child. start, center or end decides which edge of the item lines up with the container.
scroll-paddingInsets the snap area on the container, which is how you stop a sticky header covering the snapped item.
scroll-marginThe same idea on the child, useful when one item needs more clearance than the rest.
scroll-snap-stop: alwaysStops a fast flick from skipping past items, so the user moves one slide at a time.
scroll-behavior: smoothMakes programmatic jumps animate, which pairs naturally with snap points and anchor links.

Notes from practice

mandatory can trap people

With mandatory, the container must always rest on a snap point. If an item is taller than the container, parts of it become unreachable. proximity is safer for variable-height content.

It keeps native scrolling

Unlike a JavaScript carousel, momentum, trackpad gestures, keyboard scrolling and screen-reader navigation all keep working, because it is still just a scroll container.

scroll-padding solves the sticky-header overlap

Snapping to start puts the item flush against the container edge, which a sticky header then covers. scroll-padding-top on the container moves the snap line down.

CSS Scroll Snap Generator FAQ

How do I make a carousel with CSS only?

Give the container overflow-x: auto and scroll-snap-type: x mandatory, lay the slides out in a row, and set scroll-snap-align: center on each. The result scrolls natively on touch, trackpad and keyboard with no JavaScript.

What is the difference between mandatory and proximity?

mandatory forces the container to rest on a snap point every time scrolling stops. proximity only snaps when the stopping position is already close to one, which is safer when items vary in size or are taller than the container.

Why is my sticky header covering the snapped item?

Snapping to start aligns the item with the container's edge, which sits underneath the header. Add scroll-padding-top to the container equal to the header's height to move the snap line below it.

How do I stop scroll snap skipping several slides?

Set scroll-snap-stop: always on the items. A fast flick then advances one slide at a time instead of carrying past several snap points.

Does scroll snap work on mobile?

Yes, and that is where it is most useful — it is supported across current mobile browsers and preserves native touch momentum, which hand-built JavaScript carousels usually break.

Related generators

  • Flexbox — Direction, wrapping, alignment and gap, plus per-item grow, align-self and order.
  • CSS Grid — Define tracks, gaps, alignment and auto-placement, then make one item span rows and columns.
  • Aspect Ratio & Object Fit — Hold a box to a ratio, then choose how the image fills it. The dashed frame marks the original edges.
  • Scroll-driven Animation — Link an animation to scroll position with animation-timeline. Scroll the preview to see it run.

Part of CSSGen.dev — 30 free visual CSS generators with browser support built in.