HTML DOM scrollTop Property Last Updated : 09 Jun, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The DOM scrollTop property is used to return or set the number of pixels an element is scrolled vertically. If the element's content doesn't generate a scroll bar, then its scrollTop value is 0. Syntax: It returns the scrollTop property.element.scrollTopIt is used to set the scrollTop propertyelement.scrollTop = value Where value specifies the number of pixels the element's content is scrolled vertically. Note: Its value can't be negative.If the value specified is greater than the maximum scroll amount, the value is set to a maximum number. Example 1: In this example, we will use DOM scrollTop property HTML <!DOCTYPE html> <html> <head> <title>HTML DOM scrollTop Property</title> <style> #div { height: 100px; width: 250px; overflow: auto; margin: auto; } #ele { height: 300px; background-color: green; color: white; } </style> </head> <body style="text-align: center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h2> DOM scrollTop Property </h2> <div id="div" onscroll="Geeks()"> <div id="ele"> <p>GeeksforGeeks</p> <p>A computer science portal for geeks.</p> <p>Geeks classes an extensive programme for geeks.</p> </div> </div> <p id="p"></p> <script> function Geeks() { let doc = document.getElementById("div"); let x = doc.scrollTop; document.getElementById("p").innerHTML = "Vertical scroll: " + x + "px"; } </script> </body> </html> Output: Example 2: In this example, we will use HTML DOM scroll top property. HTML <!DOCTYPE html> <html> <head> <title>HTML DOM scrollTop Property</title> <style> #div { height: 100px; width: 250px; overflow: auto; margin: auto; } #ele { height: 300px; background-color: green; color: white; } </style> </head> <body style="text-align: center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h2> DOM scrollTop Property </h2> <button onclick="Geeks()">Scroll Div</button> <br> <br> <div id="div" onscroll="Geeks()"> <div id="ele"> <p>GeeksforGeeks</p> <p>A computer science portal for geeks.</p> <p>Geeks classes an extensive programme for geeks.</p> </div> </div> <script> function Geeks() { let elmnt = document.getElementById("div"); elmnt.scrollTop = 50; } </script> </body> </html> Output: Supported Browsers: The browser supported by scrollTop properties are listed below: Apple Safari 1Google Chrome 1Edge 12Firefox 1Opera 8Internet Explorer 5 Comment More infoAdvertise with us Next Article HTML DOM nodeValue Property V Vishal Chaudhary 2 Follow Improve Article Tags : Web Technologies HTML Web technologies HTML-DOM HTML-Property +1 More Similar Reads HTML DOM nodeValue Property The HTML DOM nodeValue Property is used to describe the property of a given node. It is used to set or get the nodeValue in Any Html document. Prerequisites DOM (Document Object Model) Syntax: let x = document.getElementById("nodeId").firstChild; x.nodeType; x.nodeName; x.nodeValue; Parameters: No p 1 min read HTML DOM KeyboardEvent code Property The keyboardEvent code property in HTML represents a physical key on the keyboard. It is used to return the key that triggers the event. Syntax: event.code Return Value: It returns a string that represents which key is pressed. Example 1: With KeyDown Event HTML <html> <head> <title 2 min read HTML DOM lastChild Property The DOM lastChild property is used to return the last child of the specified node. It returns the last child nodes as text, comment, or element nodes (depend on which occurs at last). It is a read-only property. Syntax: node.lastChild Return Value: It returns a node object which represents the last 2 min read HTML DOM Aside Object The DOM Aside Object is used to represent the HTML <Aside> element. The Aside element is accessed by getElementById(). The aside Element is new in HTML 5. Syntax: document.getElementById("ID"); where "id" is the ID assigned to the aside tag. Example 1: In this article, we will learn DOM Aside 2 min read HTML DOM Bold Object The DOM Bold Object is used to represent the HTML <b> element. The bold element is accessed by getElementById(). Syntax: document.getElementById("ID"); Where "id" is the ID assigned to the "b" tag. Example 1: In this example, we will use HTML DOM Bold Object HTML <!DOCTYPE html> <html 1 min read HTML DOM blur() Method The DOM blur method is used to remove the keyboard focus from the current element and also give focus with the help of the focus() method. We can apply the blur to any element and enable it by doing some operations. For example, we can blur to text-box by clicking a button. Syntax: Object.blur() Exa 1 min read HTML DOM Body Object The DOM Body Object is used to represent the HTML <Body> element. The Body element is accessed by getElementByTagName(). It can also be accessed by using a document.body object. Object Properties: Alink: It is used to sets or return the color of the active link in a Document.background: It is 2 min read HTML DOM Blockquote Object The DOM Blockquote Object is used to represent the HTML <Blockquote> element. The Blockquote element is accessed by getElementById(). Syntax document.getElementById("id"); Where "id" is the ID assigned to the blockquote tag. Property Value cite: It is used to Sets or return the value of the ci 2 min read HTML DOM Bdo Object The DOM Bdo Object is used to represent the HTML <Bdo> element. The Bidirectional element is accessed by getElementById(). Properties: It has a dir attribute which is used to set or return the text direction of an element. Syntax: document.getElementById("GFG"); Where "GFG" is the ID assigned 2 min read HTML DOM firstElementChild Property The HTML DOM firstElementChild Property will return the first child of any node PreRequisites DOM (Document Object Model) Parameters: No parameters are required. Return value: The values returned by firstElementChild property are the following: A Node object: Representing the first child element of 1 min read Like