Favorites

DOM HTMLElement.offsetWidth Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
HTMLElement.offsetWidth
DOM HTMLElement PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

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.offsetHeight

Value

The element's rendered width (or height) in whole pixels, including padding and border.

Example

<div id="box" style="width:200px;padding:10px;border:5px solid #999">Box</div>
const box = document.getElementById('box');
console.log(box.offsetWidth, box.offsetHeight);
console.log(box.clientWidth, box.scrollWidth);

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee