CSS scroll-snap-type Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Scroll Snap

What You’ll Learn

The scroll-snap-type property enables scroll snapping on a container. It defines the axis and how strictly the browser snaps to child snap targets.

01

type

Enable snap.

02

x / y

Axis choice.

03

mandatory

Strict snap.

04

proximity

Soft snap.

05

container

Scroll box.

06

align

On children.

Introduction

The scroll-snap-type property in CSS is a powerful feature that lets developers create smooth, scroll-snapping behavior for containers with overflow content.

It is especially useful for carousels, galleries, and any interface where you want precise control over scroll positions along the horizontal, vertical, or both axes.

Definition and Usage

Apply scroll-snap-type to the scroll container — the element with overflow: scroll or overflow: auto that wraps the snap targets.

Then set scroll-snap-align on child elements so the browser knows where each item should land when scrolling stops.

💡
Beginner Tip

Start with scroll-snap-type: x mandatory; on the container and scroll-snap-align: start; on each slide. That creates a simple horizontal carousel with predictable snap stops.

📝 Syntax

The syntax for the scroll-snap-type property combines an axis with a snap strictness value. It is applied to scroll containers.

syntax.css
element {
  scroll-snap-type: none | x mandatory | y proximity | both mandatory;
}
  • Axisx, y, or both sets the snapping direction.
  • Strictnessmandatory always snaps; proximity snaps when close enough.

Basic Example

scroll-container.css
.scroll-container {
  overflow-x: scroll;
  scroll-snap-type: x mandatory;
}

Related Properties

  • scroll-snap-align — sets alignment on snap targets inside the container
  • scroll-snap-stop — controls whether a snap target can be skipped during fast scrolling
  • scroll-padding — insets the scrollport on the container

🎯 Default Value

The default value of the scroll-snap-type property is none, which means no scroll snapping occurs on the container.

⚡ Quick Reference

QuestionAnswer
Default valuenone
Common valuesx mandatory, y mandatory, x proximity
Works withscroll-snap-align on snap targets
Accepted valuesnone, axis + mandatory or proximity
Set onScroll containers with overflow
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
nonescroll-snap-type: none;No snapping will occur.
x mandatoryscroll-snap-type: x mandatory;Snaps along the horizontal axis and must land on a snap point.
y mandatoryscroll-snap-type: y mandatory;Snaps along the vertical axis and must land on a snap point.
x proximityscroll-snap-type: x proximity;Snaps horizontally only when the scroll position is near a snap point.
both mandatoryscroll-snap-type: both mandatory;Snaps along both horizontal and vertical axes.
x mandatory y mandatory proximity

When to Use scroll-snap-type

scroll-snap-type helps when scroll containers need predictable snap behavior:

  • Horizontal carousels — Use x mandatory so each slide lands cleanly when scrolling stops.
  • Vertical panel flows — Use y mandatory for full-height onboarding or story sections.
  • Image galleries — Keep photos aligned consistently inside overflow scrollers.
  • Soft snapping rows — Use proximity when snapping should feel helpful but not forced.

Set scroll-snap-type on the container first, then add scroll-snap-align on each snap target inside it.

👀 Live Preview

Scroll sideways inside the box. The container uses scroll-snap-type: x mandatory.

Slide 1
Slide 2

When scrolling stops, each child snap target aligns inside the scrollport because snapping is enabled on the container.

Examples Gallery

Start with the reference horizontal carousel, try vertical snapping, compare proximity mode, then explore both-axis snapping.

📜 Container Snap Setup

Enable snapping on scroll containers — matching the reference example.

Example 1 — Horizontal scroll container with x mandatory

In this example, we’ll create a horizontal scroll container that snaps to each child element.

index.html
<style>
  .scroll-container {
    display: flex;
    overflow-x: scroll;
    scroll-snap-type: x mandatory;
    width: 100%;
  }

  .scroll-item {
    flex: none;
    scroll-snap-align: start;
    width: 100%;
    height: 200px;
    background-color: #f5a623;
    margin-right: 10px;
  }
</style>

<div class="scroll-container">
  <div class="scroll-item">Item 1</div>
  <div class="scroll-item">Item 2</div>
  <div class="scroll-item">Item 3</div>
  <div class="scroll-item">Item 4</div>
</div>
Try It Yourself

How It Works

The container turns on horizontal snapping. Each child becomes a snap target with its own alignment rule.

Example 2 — Vertical panel scroller with y mandatory

Use scroll-snap-type: y mandatory when full-height panels should snap vertically.

vertical-type.css
.panel-scroller {
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  height: 100vh;
}
Try It Yourself

How It Works

Switch the axis from x to y for vertical onboarding screens, story layouts, and section scrollers.

📄 Strictness Modes

Compare mandatory snapping with the softer proximity behavior.

Example 3 — Horizontal carousel with x proximity

Use scroll-snap-type: x proximity when snapping should happen only if the scroll position is close to a snap point.

proximity-type.css
.soft-carousel {
  overflow-x: auto;
  scroll-snap-type: x proximity;
}
Try It Yourself

How It Works

proximity is useful for card rows and galleries where users should still be able to stop between items if they want.

Example 4 — Grid gallery with both mandatory

Use scroll-snap-type: both mandatory when snap points exist along horizontal and vertical axes in the same scroller.

both-type.css
.snap-grid {
  overflow: auto;
  scroll-snap-type: both mandatory;
}
Try It Yourself

How It Works

both mandatory is less common than x or y alone, but it can power grid-like snap experiences when each tile is a snap target.

scroll-snap-type in the family

scroll-snap-type is the container property that turns snapping on. Pair it with scroll-snap-align on child snap targets and optional scroll-snap-stop when certain items must never be skipped.

container-and-target.css
.scroll-container { scroll-snap-type: x mandatory; }
.scroll-item { scroll-snap-align: start; }

🧠 How scroll-snap-type Works

1

Container enables snapping

The scroll container uses scroll-snap-type to turn on snapping along an axis.

Container
2

Targets set alignment

Child elements use scroll-snap-align so the browser knows where each snap target should land.

Target
3

Scroll motion finishes

When scrolling stops, mandatory mode forces a snap point; proximity mode snaps only if the scroll position is close enough.

Snap
=

Smooth snap scrolling

Carousels and panel scrollers feel polished because each stop lands on a defined snap target.

Browser Compatibility

The scroll-snap-type property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Scroll snap · Modern support

Reliable snap-type support

Current Chrome, Firefox, Safari, Edge, and Opera support scroll-snap-type on scroll containers.

97% Modern browser support
Google Chrome 69+ · Desktop & Mobile
Full support
Mozilla Firefox 68+ · Desktop & Mobile
Full support
Apple Safari 14.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 56+ · Modern versions
Full support

Testing tip

Test horizontal and vertical snap containers on mobile browsers to confirm mandatory and proximity modes feel natural.

scroll-snap-type property 97% supported

Bottom line: scroll-snap-type is safe to use in modern projects for scroll containers that need snap behavior.

Conclusion

The scroll-snap-type property is a valuable tool for creating intuitive and user-friendly scrolling experiences. By enabling snapping on scroll containers, you can enhance the navigational flow of carousels and panel scrollers.

Experiment with x mandatory, y mandatory, and proximity to see how each configuration changes the feel of your layout.

💡 Best Practices

✅ Do

  • Apply scroll-snap-type on the scroll container, not snap targets
  • Start with x mandatory for horizontal carousels
  • Use y mandatory for full-height vertical panel flows
  • Add scroll-snap-align on each child snap target
  • Test mandatory vs proximity on touch devices

❌ Don’t

  • Expect snapping without scroll-snap-align on child targets
  • Set scroll-snap properties on every nested element unnecessarily
  • Use mandatory everywhere if proximity feels better for your layout
  • Forget overflow scrolling on the container itself

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-snap-type

Use these points when enabling snap behavior on scroll containers.

5
Core concepts
02

x / y / both

Axis choice.

Axis
03

mandatory

Strict snap.

Mode
04

proximity

Soft snap.

Mode
05

container

Set here first.

Scope
🔄 06

scroll-snap-align

On children.

Companion

❓ Frequently Asked Questions

scroll-snap-type enables scroll snapping on a scroll container. It defines the axis (x, y, or both) and how strictly the browser must snap to snap points using mandatory or proximity.
mandatory forces the scroll container to snap to a snap point when scrolling ends. proximity snaps only when the scroll position is close enough to a snap point, allowing a freer scroll feel.
The default value is none, which means no scroll snapping occurs on the container.
Apply it to the scroll container itself — the element with overflow scroll or auto that holds the snap targets, such as a carousel wrapper or vertical panel scroller.
Use it for carousels, image galleries, onboarding screens, and any layout where each slide or panel should land at a predictable position when scrolling stops.

Practice in the Live Editor

Open the HTML editor and try scroll-snap-type: x mandatory on a horizontal carousel container.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful