Menu

gitpiper

Horizontal scroll snap css Code Snippet in 2025

interactivityintermediate

Last Updated: 22 April 2025

Creates a horizontally scrollable container that will snap on elements when scrolling.

  • Use display: grid and grid-auto-flow: column to create a horizontal layout.
  • Use scroll-snap-type: x mandatory and overscroll-behavior-x: contain to create a snap effect on horizontal scroll.
  • Change scroll-snap-align to either start, stop or center to change the snap alignment.
<div class="horizontal-snap"> <a href="#"><img src="https://picsum.photos/id/1067/640/640"></a> <a href="#"><img src="https://picsum.photos/id/122/640/640"></a> <a href="#"><img src="https://picsum.photos/id/188/640/640"></a> <a href="#"><img src="https://picsum.photos/id/249/640/640"></a> <a href="#"><img src="https://picsum.photos/id/257/640/640"></a> <a href="#"><img src="https://picsum.photos/id/259/640/640"></a> <a href="#"><img src="https://picsum.photos/id/283/640/640"></a> <a href="#"><img src="https://picsum.photos/id/288/640/640"></a> <a href="#"><img src="https://picsum.photos/id/299/640/640"></a> </div>
.horizontal-snap { margin: 0 auto; display: grid; grid-auto-flow: column; gap: 1rem; height: calc(180px + 1rem); padding: 1rem; width: 480px; overflow-y: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; } .horizontal-snap > a { scroll-snap-align: center; } .horizontal-snap img { width: 180px; max-width: none; object-fit: contain; border-radius: 1rem; }

css snippet similar to Horizontal scroll snap For You in April 2025

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2025 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️