CSS Scroll Snap Carousel
A swipeable horizontal carousel that snaps each slide into place. No JavaScript.
1
2
3
4
5
HTML
<div class="snap-row">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
CSS
.snap-row {
display: grid;
grid-auto-flow: column;
grid-auto-columns: 80%;
gap: 12px;
overflow-x: auto;
overscroll-behavior-x: contain;
scroll-snap-type: x mandatory;
scroll-padding-inline: 8px;
padding: 0 8px 8px;
}
.snap-row > * {
scroll-snap-align: start;
}
About this CSS Scroll Snap Carousel
This CSS Scroll Snap Carousel is 15 lines of pure CSS (0.3 KB) with no JavaScript and no dependencies. It uses CSS Grid and scroll snapping. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
How to use this scroll snap carousel
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.snap-rowclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.