| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll_event | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since July 2015.
The scroll event fires when an element has been scrolled.
To detect when scrolling has completed, see the scrollend event of Element.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("scroll", (event) => { })
onscroll = (event) => { }
A generic Event.
The following examples show how to use the scroll event with an event listener and with the onscroll event handler property.
The setTimeout() method is used to throttle the event handler because scroll events can fire at a high rate.
For additional examples that use requestAnimationFrame(), see the Document scroll event page.
scroll with an event listenerThe following example shows how to use the scroll event to detect when the user is scrolling inside an element:
<div id="scroll-box">
<p>Scroll me!</p>
</div>
<p id="output">Waiting on scroll events...</p>
#scroll-box {
overflow: scroll;
height: 100px;
width: 100px;
float: left;
}
#scroll-box p {
height: 200px;
width: 200px;
}
#output {
text-align: center;
}
const element = document.querySelector("div#scroll-box");
const output = document.querySelector("p#output");
element.addEventListener("scroll", (event) => {
output.textContent = "Scroll event fired!";
setTimeout(() => {
output.textContent = "Waiting on scroll events...";
}, 1000);
});
onscroll event handler propertyThe following example shows how to use the onscroll event handler property to detect when the user is scrolling:
<div id="scroll-box">
<p>Scroll me!</p>
</div>
<p id="output">Waiting on scroll events...</p>
#scroll-box {
overflow: scroll;
height: 100px;
width: 100px;
float: left;
}
#scroll-box p {
height: 200px;
width: 200px;
}
#output {
text-align: center;
}
const element = document.querySelector("div#scroll-box");
const output = document.querySelector("p#output");
element.onscroll = (event) => {
output.textContent = "Element scroll event fired!";
setTimeout(() => {
output.textContent = "Waiting on scroll events...";
}, 1000);
};
| Specification |
|---|
| CSSOM View Module # eventdef-document-scroll |
| HTML # handler-onscroll |
This page was last modified on Sep 25, 2025 by MDN contributors.
ElementactiveViewTransitionariaActiveDescendantElementariaAtomicariaAutoCompleteariaBrailleLabelariaBrailleRoleDescriptionariaBusyariaCheckedariaColCountariaColIndexariaColIndexTextariaColSpanariaControlsElementsariaCurrentariaDescribedByElementsariaDescriptionariaDetailsElementsariaDisabledariaErrorMessageElementsariaExpandedariaFlowToElementsariaHasPopupariaHiddenariaInvalidariaKeyShortcutsariaLabelariaLabelledByElementsariaLevelariaLiveariaModalariaMultiLineariaMultiSelectableariaOrientationariaOwnsElementsariaPlaceholderariaPosInSetariaPressedariaReadOnlyariaRelevantariaRequiredariaRoleDescriptionariaRowCountariaRowIndexariaRowIndexTextariaRowSpanariaSelectedariaSetSizeariaSortariaValueMaxariaValueMinariaValueNowariaValueTextassignedSlotattributeschildElementCountchildrenclassListclassNameclientHeightclientLeftclientTopclientWidthcurrentCSSZoomcustomElementRegistryelementTimingfirstElementChildidinnerHTMLlastElementChildlocalNamenamespaceURInextElementSiblingouterHTMLpartprefixpreviousElementSiblingrolescrollHeightscrollLeftscrollLeftMaxscrollTopscrollTopMaxscrollWidthshadowRootslottagNameafter()animate()append()ariaNotify()attachShadow()before()checkVisibility()closest()computedStyleMap()getAnimations()getAttribute()getAttributeNames()getAttributeNode()getAttributeNodeNS()getAttributeNS()getBoundingClientRect()getClientRects()getElementsByClassName()getElementsByTagName()getElementsByTagNameNS()getHTML()hasAttribute()hasAttributeNS()hasAttributes()hasPointerCapture()insertAdjacentElement()insertAdjacentHTML()insertAdjacentText()matches()moveBefore()prepend()pseudo()querySelector()querySelectorAll()releasePointerCapture()remove()removeAttribute()removeAttributeNode()removeAttributeNS()replaceChildren()replaceWith()requestFullscreen()requestPointerLock()scroll()scrollBy()scrollIntoView()scrollIntoViewIfNeeded()scrollTo()setAttribute()setAttributeNode()setAttributeNodeNS()setAttributeNS()setCapture()setHTML()setHTMLUnsafe()setPointerCapture()startViewTransition()toggleAttribute()afterscriptexecuteanimationcancelanimationendanimationiterationanimationstartauxclickbeforeinputbeforematchbeforescriptexecutebeforexrselectblurclickcompositionendcompositionstartcompositionupdatecontentvisibilityautostatechangecontextmenucopycutdblclickDOMActivateDOMMouseScrollfocusfocusinfocusoutfullscreenchangefullscreenerrorgesturechangegestureendgesturestartgotpointercaptureinputkeydownkeypresskeyuplostpointercapturemousedownmouseentermouseleavemousemovemouseoutmouseovermouseupmousewheelMozMousePixelScrollpastepointercancelpointerdownpointerenterpointerleavepointermovepointeroutpointeroverpointerrawupdatepointerupscrollscrollendscrollsnapchangescrollsnapchangingsecuritypolicyviolationtouchcanceltouchendtouchmovetouchstarttransitioncanceltransitionendtransitionruntransitionstartwebkitmouseforcechangedwebkitmouseforcedownwebkitmouseforceupwebkitmouseforcewillbeginwheelYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |