HTML DOM Style top Property Last Updated : 22 Apr, 2024 Comments Improve Suggest changes 1 Likes Like Report The HTML DOM Style top Property is used to set or return the top position of a positioned element including padding, scrollbar, border, and margin. Syntax: It returns the top property.object.style.topIt sets the top property.object.style.top = "auto | length | % | initial | inherit"Property Values: auto - This value automatically sets the default top value by the browser.length - This value sets the top value in the specified length units. This specified length can be positive as well as negative.% - Percentage value sets the top value in the specified percentage of the parent element’s width.initial - This value sets the top property to its browser’s default value.inherit - This value sets the top property to the value from its parent element.Return Value: A String, representing the top position of a positioned element. Example 1: In this example, we will use the HTML DOM Style top Property to set the top position of element. html <!DOCTYPE html> <html> <head> <title> HTML DOM Style top Property </title> <style> #myBtn { position: absolute; } </style> </head> <body> <h2> HTML DOM Style top Property </h2> <button id="myBtn" onclick="myFunction()"> Click here! </button> <script> function myFunction() { document.getElementById("myBtn") .style.top = "100px"; } </script> </body> </html> Output: Example 2: In this example, we will use the HTML DOM Style top Property to set the top position of element. html <!DOCTYPE html> <html> <head> <title> HTML DOM Style top Property </title> <style> #GfG { border: 1px solid black; width: 250px; text-align: center; position: relative; } </style> </head> <body> <h2>HTML DOM Style top Property</h2> <div id="GfG">Welcome to GeeksforGeeks</div> <br> <button type="button" onclick="myFunction()"> Click Here! </button> <script> function myFunction() { document.getElementById("GfG").style.top = "-20px"; } </script> </body> </html> Output: Supported Browsers: Google Chrome 1 and aboveEdge 12 and aboveInternet Explorer 5 and aboveFirefox 1 and aboveOpera 6 and aboveSafari 1 and above Create Quiz Comment D divyatagoel0709 Follow 1 Improve D divyatagoel0709 Follow 1 Improve Article Tags : Web Technologies HTML HTML-DOM HTML-Property Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables9 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List5 min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like