offsetWidth property

The offsetWidth property contains the full width of an element (includes the actual element width, border width, padding, scrollbars):

Syntax

javascriptelement.offsetWidth;

Example

Let's find out the full size of an element:

html<div id="elem"></div>
css#elem {
  width: 100px;
  height: 100px;
  padding: 15px;
  border: 10px solid black;
}
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetWidth);

The code execution result:

javascript150

Example

If an element is hidden, then offsetWidth is equal to 0:

html<div id="elem"></div>
css#elem {
  display: none; /* hidden element */
  width: 100px;
  height: 100px;
  padding: 15px;
  border: 10px solid black;
}
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetWidth);

The code execution result:

javascript0

See also

  • the clientWidth property
    that contains the width of an element inside borders
  • the offsetHeight property
    that contains the full height of an element
  • the getComputedStyle method
    that obtains the value of an element's CSS property