Skip to main content

Archive

Show more

SVG Animation Basics

SVG Animation Basics

SVG (Scalable Vector Graphics) animations allow you to create dynamic and interactive visual effects within SVG graphics. SVG supports various animation techniques, including transformations, transitions, and keyframe animations. Here's an overview of SVG animation basics:


1. Transformations

Transformations in SVG allow you to animate the position, rotation, scale, and skew of SVG elements over time. You can use attributes like transform and animateTransform to apply animations to elements.

Example:

<svg width="200" height="200">
  <rect x="0" y="0" width="50" height="50" fill="blue">
    <animateTransform attributeName="transform" attributeType="XML"
      type="rotate" from="0" to="360" dur="5s" repeatCount="indefinite" />
  </rect>
</svg>

This example rotates a blue rectangle 360 degrees over a duration of 5 seconds, repeating the animation indefinitely.


2. Transitions

Transitions in SVG allow you to animate CSS properties such as color, opacity, and size smoothly over time. You can use the transition property to specify the duration and easing function of the animation.

Example:

<svg width="200" height="200">
  <circle cx="100" cy="100" r="50" fill="blue">
    <animate attributeName="r" from="50" to="100" dur="2s" repeatCount="indefinite" />
  </circle>
</svg>

This example animates the radius of a blue circle from 50 to 100 over a duration of 2 seconds, repeating the animation indefinitely.


3. Keyframe Animations

Keyframe animations in SVG allow you to define intermediate states of an animation using keyframes. You can use the keyTimes and keySplines attributes to specify the timing and easing of keyframes.

Example:

<svg width="200" height="200">
  <circle cx="100" cy="100" r="50" fill="blue">
    <animate attributeName="cx" values="100;200;100" dur="3s" repeatCount="indefinite" />
  </circle>
</svg>

This example animates the horizontal position of a blue circle, moving it from the center to the right and back to the center over a duration of 3 seconds, repeating the animation indefinitely.


4. Conclusion

SVG animation allows you to bring your SVG graphics to life with dynamic and interactive effects. Whether using transformations, transitions, or keyframe animations, SVG provides powerful capabilities for creating engaging and visually appealing animations within your web content.

Comments