We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

script Redirect 1

A SVG script element is equivalent to the script element in HTML and thus is the place for scripts (e.g., ECMAScript).

Any functions defined within any script element have a global scope across the entire current document.

Usage context

Categories None
Permitted content Any elements or character data
Normative document SVG 1.1 (2nd Edition)


The following code snippet demonstrates the use of the SVG script tag. In this code, we use JavaScript to change the radius of the SVG <circle> element.

<svg width="100%" height="100%" viewBox="0 0 100 100"
  <script type="text/javascript">
    // <![CDATA[
    function change(evt) {
      var target = evt.target;
      var radius = target.getAttribute("r");

      if (radius == 15) {
        radius = 45;
      } else {
        radius = 15;

   // ]]>

  <circle cx="50" cy="50" r="45" fill="green"
          onclick="change(evt)" />

Live result:


Global attributes

Specific attributes

DOM interface

This element implements the SVGScriptElement interface.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.5 (1.8) 9.0 9.0 3.0.4
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 3.0 1.0 (1.8) Not supported (Yes) 3.0.4

The chart is based on these sources.

See also

Document Tags and Contributors

Last updated by: Jeremie,