Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | onscroll Attribute

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

This onscroll attribute works when an element scrollbar is being scrolled. To create a scrollbar in an element, use the CSS overflow property.

Supported Tags: It supports all HTML elements. 

Syntax: 

<element onscroll = "script">

Attribute: This attribute is supported by all HTML elements and the attribute works when script triggered.
Example: 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>onscroll attribute</title>
    <style>
        #gfg {
            border: 1px solid black;
            width: 400px;
            height: 100px;
            overflow: scroll;
            text-align: justify;
        }
         
        h1 {
            color: green;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h2>onscroll attribute</h2>
 
    <div id="gfg" onscroll="Geeks()">
      <b>GeeksforGeeks:</b> A computer science portal for
      geeks.It ia a good wqebsite for learning computer
      science. It has a good programming Question and have
      many Interwiew Experiences. Prepare for the Recruitment
      drive of product based companies like Microsoft,
      Amazon, Adobe etc with a free online placement
      preparation course. The course focuses on various
      MCQ's & Coding question likely to be asked in the
      interviews & make your upcoming placement season
      efficient and successful.
    </div>
    <script>
        function Geeks() {
            document.getElementById("gfg").style.color = "green";
        }
    </script>
</body>
</html>

Output: 

Supported Browsers: The browser supported by onscroll attribute are listed below: 

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 9
  • Firefox 6
  • Opera 11.6
  • Safari 2

My Personal Notes arrow_drop_up
Last Updated : 18 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials