The DOM offsetLeft property is used to returns the left position in pixels. This position is relative to the left side of the offsetParent element.
Syntax:
element.offsetLeft
Return Value: It returns the number representing the left position of the element in pixels.
Example:
<!DOCTYPE html> <html> <head> <title> DOM offsetLeft Property </title> <style> #GFG { height: 50px; width: 200px; padding: 10px; background-color: green; } </style> </head> <body> <h2> DOM Style offsetLeft Property </h2> <div id = "GFG"> <b>Information about this div:</b><br> <p id = "demo"></p> </div><br> <button type = "button" onclick = "geeks()"> Submit </button> <script> function geeks() { var testDiv = document.getElementById("GFG"); document.getElementById("demo").innerHTML = "offsetLeft: "+ testDiv.offsetLeft; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM offsetLeft property are listed below:
- Google Chrome
- Internet Explorer 8.0
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM lang Property
- HTML | DOM Style backgroundClip Property
- HTML | DOM Style borderTop Property
- HTML | DOM Meter max Property
- HTML | DOM Input Hidden value Property
- HTML | DOM Textarea autofocus Property
- HTML | DOM Style columnGap Property
- HTML | DOM Input Time autofocus Property
- HTML | DOM Input Submit formTarget Property
- HTML | DOM Style boxSizing Property
- HTML | DOM Video seekable Property
- HTML | DOM Input Checkbox disabled Property
- HTML | DOM Source src Property
- HTML | DOM Input Range max Property
- HTML | DOM Video loop Property
- HTML | DOM Button disabled Property
- HTML | DOM Input URL size Property
- HTML | DOM Style borderImageSource Property
- HTML | DOM Style wordBreak Property
- HTML | DOM Base target Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


