CKTIS / JavaScript
HTMLElement.offsetWidth — element layout width
HTMLElement.offsetWidth reads an element's integer width in CSS pixels, including padding and borders but excluding margins. It ignores CSS transforms.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
element.offsetWidthHTMLElement.offsetWidth is a read-only CSSOM View property, not an ECMAScript function. It returns an integer in CSS pixels. For an ordinary single box, it includes content, padding, borders, and space occupied by a vertical scrollbar, but excludes margins.
More precisely, it measures the width of the axis-aligned bounding rectangle enclosing the border boxes of all fragments generated by the element's principal box. If a block-level descendant splits the element's inline principal box, the measurement also includes the fragments generated by that descendant whose width and height are both nonzero. It ignores transforms on the element and its ancestors. Having no box, for example with display: none, produces 0.
In the example, box-sizing: content-box means the result is 100 + 2 * 10 + 2 * 2 = 124. Neither margin: 30px nor transform: scale(2) changes it. The code requires a browser document; a Node.js version alone does not establish support for this API.
Examples
const box = document.createElement('div');
box.style.cssText = 'all: initial; display: block; position: fixed; box-sizing: content-box; width: 100px; height: 20px; padding: 10px; border: 2px solid; margin: 30px; overflow: hidden; transform: scale(2);';
document.body.append(box);
console.log(box.offsetWidth);
box.style.display = 'none';
console.log(box.offsetWidth);
box.remove();Result
124 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.