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

HTML onscroll Event Attribute

❮ HTML Event Attributes


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

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

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.

Browser Support

Event Attribute
onscroll Yes Yes Yes Yes Yes


<element onscroll="script">

Attribute Values

Value Description
script The script to be run on onscroll

Technical Details

Supported HTML tags: <address>, <blockquote>, <body>, <caption>, <center>, <dd>, <dir>, <div>, <dl>, <dt>, <fieldset>, <form>, <h1> to <h6>, <html>, <li>, <menu>, <object>, <ol>, <p>, <pre>, <select>, <tbody>, <textarea>, <tfoot>, <thead>, <ul>

Related Pages

HTML DOM reference: onscroll event

❮ HTML Event Attributes