HTMLElement: offsetWidth プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTMLElement.offsetWidth は読み取り専用プロパティで、要素のレイアウト幅を整数として返します。

通常、 offsetWidth は、境界線、パディング、および垂直スクロールバー(レンダリングされている場合)を含む、要素の CSS における幅のピクセル単位の計測値です。 ::before::after などの擬似要素の幅は含まれません。

要素が非表示の場合、(例えば、要素またはその祖先のいずれかで style.display"none" に設定している場合) 0 が返されます。

要素の offsetWidth ピクセル値に対応する整数です。 offsetWidth プロパティは読み取り専用です。

メモ: このプロパティは、値を整数に丸めます。 小数値が必要な場合は、element.getBoundingClientRect() を使用してください。

大きなパディング、境界、マージンを持つ要素の例です。offsetWidth` は、パディングと境界を含み、マージンを除いた要素のレイアウト幅である。

仕様書

Specification
CSSOM View Module
# dom-htmlelement-offsetwidth

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
offsetWidth

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報