SVG Animation

SVG (Scalable Vector Graphics) animation is a powerful way to create interactive and dynamic graphics on the web. SVG allows you to describe two-dimensional vector graphics, and with the help of CSS and JavaScript, you can bring these graphics to life through animations.

Here’s a simple example of an SVG animation using CSS:

Html Code

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<style>
@keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

#animated-circle {
fill: #3498db;
animation: rotate 2s linear infinite;
}
</style>
</head>
<body>
<svg width=”100″ height=”100″ xmlns=”http://www.w3.org/2000/svg”>
<circle cx=”50″ cy=”50″ r=”40″ id=”animated-circle” />
</svg>
</body>
</html>

In this example:

  • @keyframes rotate defines a CSS animation named “rotate” that smoothly rotates an element from 0 to 360 degrees.
  • #animated-circle selects the circle element within the SVG and applies the animation to it. The fill property is used to set the color of the circle.

You can customize the animation duration, timing function, and other properties based on your requirements. Additionally, JavaScript can be used for more complex interactions and animations.

Leave a Reply