DOM HTMLElement.offsetWidth Property
The offsetWidth property returns the width of an element as displayed, including padding and border. offsetHeight returns its height.
Description
The read-only offsetWidth and offsetHeight properties give the element's layout size in pixels, including padding, border and scroll bars, but not margins. They're rounded to whole numbers and ignore CSS transforms; getBoundingClientRect() gives exact, transformed values. Elements that aren't displayed return 0.
Reading these properties forces the browser to calculate layout if anything has changed, so reading them in a loop that also changes styles can cause slow "layout thrashing". Read all the values you need first, then make your changes.
Related properties include clientWidth, which leaves out borders and scroll bars, and scrollWidth, which includes content that has overflowed. offsetTop and offsetLeft give the position relative to the nearest positioned ancestor.
Syntax
element.offsetWidth
element.offsetHeightValue
The element's rendered width (or height) in whole pixels, including padding and border.
Example
Browser Support
The following information will show you the current browser support for the HTMLElement.offsetWidth property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





