Web/API/SVGRectElement

From Get docs


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.x Read only
Returns an SVGAnimatedLength corresponding to the x attribute of the given <rect> element.
SVGRectElement.y Read only
Returns an SVGAnimatedLength corresponding to the y attribute of the given <rect> element.
SVGRectElement.width Read only
Returns an SVGAnimatedLength corresponding to the width attribute of the given <rect> element.
SVGRectElement.height Read only
Returns an SVGAnimatedLength corresponding to the height attribute of the given <rect> element.
SVGRectElement.rx Read only
Returns an SVGAnimatedLength corresponding to the rx attribute of the given <rect> element.
SVGRectElement.ry Read only
Returns an SVGAnimatedLength corresponding to the ry attribute 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

Specification Status Comment
Scalable Vector Graphics (SVG) 2The definition of 'SVGRectElement' in that specification. Candidate Recommendation Replaced the inheritance from SVGElementSVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, and SVGTransformable by SVGGeometryElement
Scalable Vector Graphics (SVG) 1.1 (Second Edition)The definition of 'SVGRectElement' in that specification. Recommendation Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
SVGRectElement Chrome

Full support Yes

Edge Full support 12

Notes'

Full support 12

Notes'

Notes' Before Edge 79, this interface implements only the SVG 1.1 specification.

Firefox Full support Yes

Notes'

Full support Yes

Notes'

Notes' Only implements the SVG 1.1 specification of the interface.

IE Full support 9

Notes'

Full support 9

Notes'

Notes' Only implements the SVG 1.1 specification of the interface.

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android Full support Yes

Notes'

Full support Yes

Notes'

Notes' Only implements the SVG 1.1 specification of the interface.

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

height Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

rx Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

ry Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

width Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

x Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

y Chrome

Full support Yes

Edge

Full support 12

Firefox

Full support Yes

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.'
See implementation notes.


See also