Interactivity
Utilities for controlling how strictly snap points are enforced in a snap container.
Class | Styles |
---|---|
snap-none | scroll-snap-type: none; |
snap-x | scroll-snap-type: x var(--tw-scroll-snap-strictness); |
snap-y | scroll-snap-type: y var(--tw-scroll-snap-strictness); |
snap-both | scroll-snap-type: both var(--tw-scroll-snap-strictness); |
snap-mandatory | --tw-scroll-snap-strictness: mandatory; |
snap-proximity | --tw-scroll-snap-strictness: proximity; |
Use the snap-x
utility to enable horizontal scroll snapping within an element:
Scroll in the grid of images to see the expected behavior
For scroll snapping to work, you need to also set the scroll snap alignment on the children.
Use the snap-mandatory
utility to force a snap container to always come to rest on a snap point:
Scroll in the grid of images to see the expected behavior
Use the snap-proximity
utility to make a snap container come to rest on snap points that are close in proximity:
Scroll in the grid of images to see the expected behavior
Prefix a scroll-snap-type
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<div class="snap-none md:snap-x ..."> <!-- ... --></div>
Learn more about using variants in the variants documentation.