SnapEvent: SnapEvent() constructor

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() constructor creates a new SnapEvent object instance.

Syntax

js
new SnapEvent(type, init)

Parameters

type

A string representing the type of event. For scrollsnapchanging events, this is scrollsnapchanging. For scrollsnapchange events, this is scrollsnapchange.

init

An object containing the following properties:

snapTargetBlock Optional

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 Optional

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

A developer would not use this constructor manually. A new SnapEvent object is constructed when a handler is invoked as a result of the scrollsnapchanging or scrollsnapchange events firing.

For example:

js
mainElem.addEventListener("scrollsnapchange", (event) => {
  // …

  // Log a SnapEvent object instance to the console
  console.log(event);
});

Specifications

Specification
CSS Scroll Snap Module Level 2
# dom-snapevent-snapevent

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() 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

Legend

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

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

See also