Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

HTML onscroll Attribute


Definition and Usage

The onscroll attribute fires when an element's scrollbar is being scrolled.

Tip: use the CSS overflow style property to create a scrollbar for an element.


Applies to

The onscroll attribute is part of the Event Attributes, and can be used on any HTML elements.

Elements Event
All HTML elements onscroll

Example

Div Example

Execute a JavaScript when a <div> element is being scrolled:

<div onscroll="myFunction()">
Try it Yourself »

Browser Support

Event Attribute
onscroll Yes Yes Yes Yes Yes