Favorites

HTML onscrollsnapchange Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onscrollsnapchange
HTML Event AttributeThis event attribute is supported in some modern browsers, but not all.
Updated 22nd November 2026

Description

The onscrollsnapchange event attribute runs a script on a scroll snap container when a new snap target has been selected, at the end of a scroll. Use it to update the page once the user has settled on a new slide or section, for example to highlight the matching navigation dot.

The event is a SnapEvent with two properties: snapTargetBlock and snapTargetInline, the elements snapped to in the block and inline directions (or null). It does not fire if the scroll ends at the same snap target it started on. To react while the user is still scrolling, use onscrollsnapchanging.

Syntax

<element onscrollsnapchange="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onscrollsnapchange event</title>
<style>
#scroller {
display: flex;
width: 300px;
overflow-x: auto;
scroll-snap-type: x mandatory;
}
#scroller div {
flex: 0 0 100%;
height: 120px;
scroll-snap-align: start;
background: #dde3ff;
}
#scroller div:nth-child(2) { background: #c9d2ff; }
</style>
</head>
<body>
<div id="scroller" onscrollsnapchange="document.getElementById('info').textContent = 'Snapped to: ' + event.snapTargetInline.textContent">
<div>Slide 1</div><div>Slide 2</div><div>Slide 3</div>
</div>
<p id="info"></p>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onscrollsnapchange event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee