Advanced SMIL: Shape Morphing

Shape morphing is one of the most powerful and visually impressive features of SVG animation. It allows you to smoothly transition a shape from one form to another by animating its d (data) attribute.

While CSS can handle simple movements and rotations, path data morphing is where SMIL has the edge.

How Morphiing Works

To morph a shape, you use the standard <animate> tag and target the attributeName="d" property. You provide a "from" path and a "to" path (or a list of paths in the values attribute).

The Golden Rule of Morphing

For a browser to smoothly interpolate between two paths, they must have the same structure. Specifically:

If the point counts don't match, the browser won't know how to transition between them, and the shape will "snap" or flicker instantly from one state to the next without any smooth motion.

Example: Path Morphing

In the examples below, we demonstrate a transformation from a square to a star, and a functional example of an "eye" blinking by morphing the curves of its path.

View Output

Tips for Better Morphing