In JavaScript, the Document scroll event fires when the document view has been scrolled (MDN). Read position with window.scrollY / scrollX. A generic Event.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for scroll. Start with this line.
JavaScript
addEventListener("scroll", fn)
Call
What it does
addEventListener("scroll", fn)
Primary signature.
Built into the browser. Listen with document.addEventListener("scroll", …) — no import required.
Library declarations
JavaScript
addEventListener("scroll", fn)
Parameters
Parameter
Description
Listener on document
Required. Document-view scroll signal
Throttle (setTimeout)
Optional. Limit work rate (MDN)
Return Value
Return Value
Description
*
Fires as a Document event (listener receives the Event object).
JavaScript Examples
Example 1 — Log scrollY
Show the vertical scroll position whenever the document view scrolls.
scrollY < 200 → button hidden
scrollY ≥ 200 → button visible
click → smooth scroll to top
How It Works
Compare scrollY. Show the button only after ~200px.
Passive listener. Scroll handlers often do not call preventDefault.
Click to reset.scrollTo({ top: 0, behavior: "smooth" }).
Keep the check cheap. A boolean toggle is fine on every scroll.
Compatibility
Browser Support
Documentscroll is Baseline Widely available (MDN, since July 2015). It is a standard Document event — not Deprecated, Experimental, or Non-standard.
✓ Baseline · Widely available
Document scroll
Fires when the document view has been scrolled. Pair with window.scrollY and throttle expensive work.
99%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
Document scrollExcellent
Bottom line: Safe everywhere students build today. Keep handlers light, throttle with setTimeout when needed, and use scrollend or IntersectionObserver when that fits better.
Frequently Asked Questions
It fires when the document view has been scrolled. For element overflow scrolling, use the Element scroll event. To detect when scrolling has finished, see Document scrollend (MDN).
No. MDN marks Document scroll as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Scroll fires at a high rate. Avoid heavy DOM work on every event. MDN recommends throttling with setTimeout (measure your own timeout). Using requestAnimationFrame alone to throttle scroll is not useful because it runs at a similar rate.
Commonly use window.scrollY (and window.scrollX). You can also use document.scrollingElement.scrollTop for the scrolling root element.
Yes. You can use document.onscroll or document.addEventListener("scroll", …).
MDN suggests IntersectionObserver for threshold-based listening (for example, when a section enters the viewport) instead of computing visibility on every scroll event.