Favorites

DOM Window: scroll event

☕
Enjoying this site?

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

Buy us a coffee
Window: scroll event
DOM Window EventThis event is supported by all modern browsers.
Updated 28th November 2026

The scroll event fires when the page or a scrollable element is scrolled.

Description

The scroll event fires when the document or an element is scrolled. It fires very often, so keep handlers quick and pass { passive: true }. For effects tied to elements entering the screen, IntersectionObserver is far more efficient, and CSS scroll-driven animations can replace many scroll handlers entirely. The scrollend event fires once scrolling stops.

The event fires after the scroll has happened, so calling preventDefault() can't stop scrolling; to block scrolling, use CSS such as overflow: hidden. Scroll events on elements don't bubble, so listen on the scrolling element itself, or on the document with the capture option.

Listeners for window events are added with window.addEventListener(). The older way, assigning a function to a property such as window.onresize, only allows one handler, so a second assignment replaces the first.

Syntax

window.addEventListener('scroll', handler, { passive: true })

Example

<div id="bar" style="position:fixed;top:0;left:0;height:4px;background:#2563eb;width:0"></div>
<div style="height:1200px;padding-top:12px">Scroll down to fill the progress bar.</div>
const bar = document.getElementById('bar');
window.addEventListener('scroll', () => {
  const max = document.documentElement.scrollHeight - innerHeight;
  bar.style.width = (scrollY / max) * 100 + '%';
}, { passive: true });
console.log('Scroll the frame');

Browser Support

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

This event is supported by all modern browsers.

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