html tutorial - onscroll Attribute in HTML - html5 - html code - html form

Onscroll attribute in html

Learn html - html tutorial - Onscroll attribute in html - html examples - html programs

  • The onscroll attribute triggers when the element’s scrollbar is being scrolled.
  • onscroll attribute is the part of the event attribute.

Syntax for onscroll attribute in HTML:

<div onscroll="myFunction()">

Differences between HTML 4.01 and HTML5 for onscroll attribute:

HTML 4.01

  • HTML4 does not support onscroll attribute.


  • HTML5 supports onscroll attribute.

Applies To:

Element Attribute
All Visible elements onscroll

Attribute Values:

Value Description
script The script can run on onscroll

Sample Coding for onscroll Attribute in HTML:

Tryit<!DOCTYPE html>
         <title>Wikitechy onscroll attribute</title>
               #myDIV {
               border: 1px solid black;
               width: 300px;
               height: 150px;
               overflow: scroll;
        <h3>Welcome to</h3>
        <h5>Wikitechy technology tutorials</h5>
        <p>To need more details scroll down:</p>
        <div id="myDIV" onscroll="OnScroll()">Wikitechy tutorials includes various technologies like HTML,CSS,GITHUB,ANGULAR JS etc.,>
            HTML - Hyper Text Markup Language.HTML is a typical markup language used for building a web pages.
            The word "Markup" means a language with particular syntax which instructs a Web browser to how the
            page needs to display.HTML uses a pre-defined set of elements called tags. A group of elements 
            which is join together to build the web page.HTML tags defines elements like "paragraph",
            "body", and so on.
            function OnScroll() 
             document.getElementById("myDIV").style.color = "blue";

Code Explanation for onscroll Attribute in HTML:

onscroll Attribute Code Explanation

  1. “myDIV” is used to apply styles to the
  2. <div id=”myDIV”> is used to display block of contents with specified style.
  3. The onscroll attribute is used to call OnScroll() JavaScript function when the content inside the scrollbar is scrolled.
  4. The JavaScript function OnScroll() is used to display the content in blue color when scrolled.

Output for onscroll Attribute in HTML:

onscroll Attribute Tag Output

  1. The output shows the contents.
  2. onscroll Attribute Tag Output
  3. When user scroll downwards the text turns into blue color.

Browser Support for onscroll Attribute in HTML:

Yes Yes Yes Yes Yes

Related Searches to onscroll Attribute in html