SnapEvent

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The SnapEvent interface defines the event object for the scrollsnapchanging and scrollsnapchange events. Respectively, these fire on a scroll container when the browser determines that a new scroll snap target is pending (will be selected when the current scroll gesture ends), and when a new snap target is selected.

These events can be used to run code in response to new elements being snapped to; SnapEvent exposes references to the element snapped to in the inline and/or block direction. The property values available on SnapEvent correspond directly to the value of the scroll-snap-type CSS property set on the scroll container:

  • If the snap axis is specified as block (or a physical axis value that equates to block in the current writing mode), only snapTargetBlock returns an element reference.
  • If the snap axis is specified as inline (or a physical axis value that equates to inline in the current writing mode), only snapTargetInline returns an element reference.
  • If the snap axis is specified as both, snapTargetBlock and snapTargetInline return an element reference.
Event SnapEvent

Constructor

SnapEvent()

Creates a new SnapEvent object instance.

Instance properties

Inherits properties from its parent, Event.

snapTargetBlock Read only

Returns a reference to the element snapped to in the block direction when the event fired, or null if scroll snapping only occurs in the inline direction so no element is snapped to in the block direction.

snapTargetInline Read only

Returns a reference to the element snapped to in the inline direction when the event fired, or null if scroll snapping only occurs in the block direction so no element is snapped to in the inline direction.

Examples

scrollsnapchanging example

In the following scrollsnapchanging handler function snippet, we set the snapTargetBlock element's class attribute to pending using the Element.className property, which could be used to style the element differently when it becomes a pending snap target.

Note that this handler is intended to be set on a block-direction scroll container (vertically-scrolling if the page is set to a horizontal writing-mode), therefore only the snapTargetBlock element will change between multiple events firing. SnapEvent.snapTargetInline will return null, because no snapping occurs in the inline direction.

js
scrollingElem.addEventListener("scrollsnapchanging", (event) => {
  // Set current pending snap target class to "pending"
  event.snapTargetBlock.className = "pending";

  // Logs the new pending block-direction snap target element
  console.log(event.snapTargetBlock);

  // Logs null; no inline snapping occurs
  console.log(event.snapTargetInline);
});

scrollsnapchange example

In the following scrollsnapchange handler function snippet, we set a selected class on the SnapEvent.snapTargetBlock element, which could be used to style a newly-selected snap target to look like it has been selected (for example, with an animation).

js
scrollingElem.addEventListener("scrollsnapchange", (event) => {
  event.snapTargetBlock.className = "selected";
});

Specifications

Specification
CSS Scroll Snap Module Level 2
# snapevent-interface

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
SnapEvent
Experimental
Chrome – Full support
Chrome 129 (Release date: 2024-09-17)
footnote Full support
Edge – Full support
Edge 129 (Release date: 2024-09-19)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1843961
Opera – Full support
Opera 115 (Release date: 2024-11-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 129 (Release date: 2024-09-17)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1843961
Opera Android – Full support
Opera Android 86 (Release date: 2024-12-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 129 (Release date: 2024-09-17)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
SnapEvent() constructor
Experimental
Chrome – No support
Chrome 138 (Release date: 2025-06-24)
disabled
disabled From version 138 users must explicitly set the #enable-experimental-web-platform-features preference to true. To change preferences in Chrome, visit chrome://flags.
Edge – No support
Edge 138 (Release date: 2025-06-26)
disabled
disabled From version 138 users must explicitly set the #enable-experimental-web-platform-features preference to true. To change preferences in Edge, visit about:flags.
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera 122 (Release date: 2025-09-11)
disabled
disabled From version 122 users must explicitly set the #enable-experimental-web-platform-features preference to true. To change preferences in Opera, visit opera://flags.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android 138 (Release date: 2025-06-24)
disabled
disabled From version 138 users must explicitly set the #enable-experimental-web-platform-features preference to true. To change preferences in Chrome Android, visit chrome://flags.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
snapTargetBlock
Experimental
Chrome – Full support
Chrome 129 (Release date: 2024-09-17)
footnote Full support
Edge – Full support
Edge 129 (Release date: 2024-09-19)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 115 (Release date: 2024-11-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 129 (Release date: 2024-09-17)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 86 (Release date: 2024-12-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 129 (Release date: 2024-09-17)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
snapTargetInline
Experimental
Chrome – Full support
Chrome 129 (Release date: 2024-09-17)
footnote Full support
Edge – Full support
Edge 129 (Release date: 2024-09-19)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 115 (Release date: 2024-11-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 129 (Release date: 2024-09-17)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 86 (Release date: 2024-12-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 129 (Release date: 2024-09-17)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.

See also