Open In App

SVG <animate> Element

SVG stands for Scalable Vector Graphic. It can be used to make graphics and animations like in HTML canvas.

The <animate> SVG element is used to animate an attribute or property of an element over time. It’s normally inserted inside the element which we want to animate.



Syntax:

<animate attributeName="" values="" dur="" repeatCount="" />

Attributes:



Below given are a few examples of the above element: 

Example 1: 




<!DOCTYPE html>
<html>
 
<body>
    <svg viewBox="0 0 50 50">
        <rect width="10" height="10" fill="green">
            <animate attributeName="rx" values="0;20;0"
                dur="2s" repeatCount="10" />
        </rect>
    </svg>
</body>
 
</html>

Output:

 

Example 2: 




<!DOCTYPE html>
<html>
 
<body>
    <h1 style="color:green">
        GeeksforGeeks
    </h1
    <h2>
        SVG animate element
    </h2
    <svg viewBox="0 0 50 50">
        <rect width="7" height="7" fill="green">
            <animate attributeType="CSS" attributeName="opacity"
           from="1" to="0" dur="4s" repeatCount="indefinite" />
        </rect>
    </svg>
</body>
 
</html>

Output:

Browsers Supported: The following browsers are supported by this SVG element:


Article Tags :