Open In App

What is the purpose of the scroll-snap-type Property in CSS ?

Last Updated : 02 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The scroll-snap-type property in CSS is used to control the snapping behavior of scroll positions within a scroll container. It defines how the scrolling alignment should occur when users scroll through a container, creating a smooth and controlled scrolling experience.

Note: The scroll-snap-type property can take values like none, mandatory, and proximity

Syntax:

/* Enabling mandatory scroll snapping for both X and Y axes */
.scroll-container {
scroll-snap-type: mandatory both;
}

Features:

  • scroll-snap-type Property:
    • none: Disables scroll snapping.
    • mandatory: Enforces snap points, ensuring that the scroll container always stops at specified positions.
    • proximity: Suggests snap points, allowing the browser to choose the best snap point based on proximity.
  • Axis Specificity: You can specify scroll snapping behavior for the X and Y axes separately.
  • Compatibility: Check for browser support, as older browsers may not fully support the scroll-snap-type property.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads