このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

SVGRectElement: width プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

widthSVGRectElement インターフェイスの読み取り専用のプロパティで、 SVG 矩形の水平方向のサイズを SVGAnimatedLength として表します。長さは、x 軸方向のユーザー座標系の単位で表されます。構文は、 <length> と同じです。

これは、 <rect> 要素のプレゼンテーション属性 width を反映します。 CSS のプロパティ width が、SVG のプレゼンテーション属性 width よりも優先されるため、この値は要素の実際のサイズを反映しない場合があります。既定値は 0 です。

SVGAnimatedLength です。

js
const rectangle = document.querySelector("rect");
const rectWidth = rectangle.width;
console.log(rectWidth.baseVal.value); // `width` の値

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGRectElement__width

ブラウザーの互換性

関連情報