HTML | DOM Style position Property Last Updated : 29 Nov, 2022 Comments Improve Suggest changes Like Article Like Report The position property sets or returns the type of positioning method used by the element. It may be static, relative, absolute or fixed. Syntax: Return position syntax: object.style.position Set position syntax: object.style.position = "static | absolute | fixed | relative | sticky | initial | inherit" Return Value: It returns a string which represents the position type of the element. Properties: static: It is the default property. The appearance of elements in the document remains static in accordance with the document flow. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { // change position from relative // to static. document.getElementById( "gfg").style.position = "static"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: absolute: It positions the element relative to the first positioned element. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <p> <h4>DOM Style Position Property</h4></p> </div> <script> function position() { // Set position from // relative to absolute. document.getElementById( "gfg").style.position = "absolute"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: fixed: It positions the elements relative to the browser window. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { document.getElementById( "gfg").style.position = "fixed"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: relative: It positions the elements relative to the normal position, so "right:40" signifies an addition of 40 pixels to the element's RIGHT position. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { document.getElementById( "gfg").style.position = "relative"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: sticky: It positions the elements based on the scroll position of the user.The scrolling operation is performed between relative and fixed property values. By default, the scroll position is set at relative value. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { document.getElementById( "gfg").style.position = "sticky"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Note:Internet Explore does not support this property value and Apple Safari supports this property from 6.1 version. initial: It sets the position to it's default value. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { document.getElementById( "gfg").style.position = "initial"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: inherit: It inherits the position values of the parent element. Example: html <!DOCTYPE html> <html> <head> <h1> <center>Geeks <button onclick="position()"> Press </button> </center> </h1> <br> <style> #gfg { border: 1px solid black; background-color: green; width: 215px; height: 60px; position: relative; top: 100px; } </style> </head> <body> <div id="gfg"> <h4>DOM Style Position Property</h4> </div> <script> function position() { document.getElementById( "gfg").style.position = "inherit"; } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Browser Support: The browsers supported by DOM position property are listed below: Google Chrome 1 Edge 12 Internet Explorer 4 Firefox 1 Opera 4 Safari 1 Create Quiz Comment R riarawal99 Follow 0 Improve R riarawal99 Follow 0 Improve Article Tags : Web Technologies HTML HTML-DOM 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 List15+ 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