Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Pro

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


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