Web/API/SVGCircleElement

From Get docs


The SVGCircleElement interface is an interface for the <circle> element.

Properties

This interface also inherits properties from its parent, SVGGeometryElement.

SVGCircleElement.cx Read only
This property defines the x-coordinate of the center of the <circle> element. It is denoted by the cx attribute of the element.
SVGCircleElement.cy Read only
This property defines the y-coordinate of the center of the <circle> element. It is denoted by the cy attribute of the element.
SVGCircleElement.r Read only
This property defines the radius of the <circle> element. It is denoted by the r of the element.

Methods

This interface has no methods but inherits methods from its parent, SVGGeometryElement.

Example

SVG content

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 250 250" width="250" height="250">
  <circle cx="100" cy="100" r="50" fill="gold" id="circle"
      onclick="clickCircle();"/> 
</svg>

JavaScript content

This function clickCircle() is called when the circle is clicked. It randomly increases or decreases the radius of the circle element.

function clickCircle() {
  var circle = document.getElementById("circle");
  // Randomly determine if the circle radius will increase or decrease
  var change = Math.random() > 0.5 ? 10 : -10;
  // Clamp the circle radius to a minimum of 10 and a maximum of 250,
  // so it won't disappear or get bigger than the viewport
  var newValue = Math.min(Math.max(circle.r.baseVal.value + change, 10), 250);
  circle.setAttribute("r", newValue);
}

Click on the circle.

Specifications

Specification Status Comment
Scalable Vector Graphics (SVG) 2The definition of 'SVGCircleElement' in that specification. Candidate Recommendation Replaced the inheritance from SVGElement, SVGTests, SVGLangSpace, SVGExternalResourcesRequired, SVGStylable, and SVGTransformable by SVGGeometryElement
Scalable Vector Graphics (SVG) 1.1 (Second Edition)The definition of 'SVGCircleElement' 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
SVGCircleElement Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 1.5

IE

Full support 9

Opera

Full support 8

Safari

Full support 3.1

WebView Android

Full support 3

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support 3.1

Samsung Internet Android

Full support 1.0

cx 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

cy 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

r 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 also