SVGRectElement
The SVGRectElement interface provides access to the properties of <rect> elements, as well as methods to manipulate them.
Properties
This interface also inherits properties from its parent, SVGGeometryElement.
-
SVGRectElement.xRead only -
Returns an
SVGAnimatedLengthcorresponding to thexattribute of the given<rect>element. -
SVGRectElement.yRead only -
Returns an
SVGAnimatedLengthcorresponding to theyattribute of the given<rect>element. -
SVGRectElement.widthRead only -
Returns an
SVGAnimatedLengthcorresponding to thewidthattribute of the given<rect>element. -
SVGRectElement.heightRead only -
Returns an
SVGAnimatedLengthcorresponding to theheightattribute of the given<rect>element. -
SVGRectElement.rxRead only -
Returns an
SVGAnimatedLengthcorresponding to therxattribute of the given<rect>element. -
SVGRectElement.ryRead only -
Returns an
SVGAnimatedLengthcorresponding to theryattribute of the given<rect>element.
Methods
This interface doesn't implement any specific methods, but inherits methods from its parent, SVGGeometryElement.
Example
Here is a simple usage of rect interface. (Changing the color of the rect interface on every click)
SVG content
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect width="300" height="100" id="myrect" onclick="doRectClick()" style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)" /> <text x="60" y="40" fill="white" font-size="40" onclick="doRectClick();">Click Me</text> </svg>
JavaScript content
function doRectClick(){ var myrect = document.getElementById('myrect'); var r = Math.floor(Math.random() * 255); var g = Math.floor(Math.random() * 255); var b = Math.floor(Math.random() * 255); myrect.style.fill = 'rgb(' + r + ', ' + g + ' , ' + b + ')'; }
Click the rect.
Specifications
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
SVGRectElement |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
height |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
rx |
1 |
12 |
1.5 |
9 |
≤12.1 |
4 |
≤37 |
18 |
4 |
≤12.1 |
3.2 |
1.0 |
ry |
1 |
12 |
1.5 |
9 |
≤12.1 |
4 |
≤37 |
18 |
4 |
≤12.1 |
3.2 |
1.0 |
width |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
x |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
y |
1 |
12 |
1.5 |
9 |
≤12.1 |
3 |
≤37 |
18 |
4 |
≤12.1 |
1 |
1.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SVGRectElement