SVGRectElement: width property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The width
read-only property of the SVGRectElement
interface describes the horizontal size of an SVG rectangle as a SVGAnimatedLength
. The length is in user coordinate system units along the x-axis. Its syntax is the same as that for <length>
.
It reflects the <rect>
element's width
presentational attribute. The CSS width
property takes precedence over the SVG width
presentational attribute, so the value may not reflect the elements actual size. The default value is 0
.
Value
Example
js
const rectangle = document.querySelector("rect");
const rectWidth = rectangle.width;
console.log(rectWidth.baseVal.value); // the `width` value
Specifications
Specification |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGRectElement__width |
Browser compatibility
BCD tables only load in the browser