How to Animate an SVG with CSS
You can move some SVG properties to CSS and even animate them with CSS keyframes. In this example, we create a spinning windmill.
Draw the head of the windmill
Let’s start by composing the windmill’s head. Thanks to its central symmetry, we can define a single arm and reuse this element with a rotation.
How to Draw Basic Paths with SVGWe define the arm as a path. We start with the move-to command, draw a cubic Bézier curve curve, then finish the shape with two straight lines. Hover over the coordinates in the code or on the image to see how they are positioned.
To finish the head of the windmill, we reuse the same arm element with a rotation and add a circle to the middle.
Finish the windmill and add CSS animation
To finish the windmill, we add a stand and wrap the head of the windmill into two group elements. The outer group positions the head, and the inner will do the rotation.
We translate
the outer group by -50 units to position the head.
We assign the id windmill-head
to the inner group and set a keyframe animation in CSS that rotates the head.
When we set the rotation in CSS, we need to add the unit of measurement.