CSS scroll-snap-type Property

❮ Previous Reference Next ❯

Example

.scroller {
  text-align: left;
  width: 250px;
  height: 250px;
  overflow-x: scroll;
  display: flex;
  flex-direction: row;
  box-sizing: border-box;
  border: 1px solid #000;
  scroll-snap-type: x mandatory;
  scroll-padding: 2rem;
}





1
2
3

Meaning:

The scroll-snap-type CSS property sets how strictly snap points are enforced on the scroll container in case there is one.

Specifying any precise animations or physics used to enforce those snap points is not covered by this property but instead left up to the user agent.

Default value:none
Inherited:No
Animatable:No
Version:CSS3
JavaScript syntax:
object.style.scrollSnapType="none|x|y|block|inline|both|mandatory|proximity|initial|inherit|revert|revert-layer|unset";



Standard Syntax

scroll-snap-type: none|x|y|block|inline|both|mandatory|proximity|initial|inherit|revert|revert-layer|unset;



Browser Support




Status







Property Values

The following table describes the values of this property:

Value Description
none When the visual viewport of this scroll container is scrolled, it must ignore snap points.
x The scroll container snaps to snap positions in its horizontal axis only.
y The scroll container snaps to snap positions in its vertical axis only.
block The scroll container snaps to snap positions in its block axis only.
inline The scroll container snaps to snap positions in its inline axis only.
both The scroll container snaps to snap positions in both of its axes independently (potentially snapping to different elements in each axis).
mandatory The visual viewport of this scroll container will rest on a snap point if it isn't currently scrolled. That means it snaps on that point when the scroll action finished, if possible. If content is added, moved, deleted or resized the scroll offset will be adjusted to maintain the resting on that snap point.
proximity The visual viewport of this scroll container may come to rest on a snap point if it isn't currently scrolled considering the user agent's scroll parameters. If content is added, moved, deleted or resized the scroll offset may be adjusted to maintain the resting on that snap point.
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element animation-delay property.
revert Reverts the cascaded value of the property from its current value to the value the property
revert-layer Rollback styles to the ones specified in previous cascade layers.
unset Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not.



Default CSS Property Values

selectors {
  scroll-snap-type: none;
}
❮ Previous Reference Next ❯