HTML | DOM offsetWidth Property
The DOM offsetWidth property is used to returns the layout width of an element as an integer. It is measured in pixels. It includes width, border, padding, and vertical scrollbars but not margin. If the element is hidden then it returns 0.
Syntax:
element.offsetWidth
Return Value: It returns the layout width of an element as an integer.
Example 1:
<!DOCTYPE html> <html> <head> <title> DOM Style offsetWidth Property </title> <style> #GFG { height: 150px; width: 300px; padding: 10px; margin: 15px; background-color: green; } </style> </head> <body> <h2>DOM Style offsetWidth Property</h2> <div id="GFG"> <b>Information about this div:</b> <p id="demo"></p> </div> <button type="button" onclick="Geeks()"> Submit </button> <script> function Geeks() { var elmnt = document.getElementById("GFG"); var txt = "Width including padding and border: " + elmnt.offsetWidth + "px"; document.getElementById("demo").innerHTML = txt; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Example 2:
<!DOCTYPE html> <html> <head> <title> DOM Style offsetWidth Property </title> <style> #GFG { height: 150px; width: 300px; padding: 10px; margin: 15px; background-color: green; } </style> </head> <body> <h2>DOM Style offsetWidth Property</h2> <div id="GFG"> <b>Information about this div:</b> <br> <p id="demo"></p> </div> <button type="button" onclick="Geeks()"> Submit </button> <script> function Geeks() { var elmnt = document.getElementById("GFG"); var txt = ""; txt += "Width with padding: " + elmnt.clientWidth + "px<br>"; txt += "Width with padding and border: " + elmnt.offsetWidth + "px"; document.getElementById("demo").innerHTML = txt; } </script> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM offsetWidth property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- offsetWidth, clientWidth, scrollWidth and Height, respectively in CSS
- HTML | DOM Bdo dir Property
- HTML | DOM URL Property
- HTML | DOM value Property
- HTML | DOM dir Property
- HTML | DOM name Property
- HTML | DOM specified Property
- HTML | DOM id Property
- HTML | DOM li value Property
- HTML | DOM innerText Property
- HTML | DOM KeyboardEvent key Property
- HTML | DOM Anchor rel Property
- HTML | DOM Button name Property
- HTML | DOM Ol type Property
- HTML | DOM del cite 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.



