StealThis .dev

SVG Path Morph

A self-contained SVG shape morphing demo that smoothly interpolates between icons and blobs by tweening normalized path point sets — with easing, autoplay on a timer, play/pause, and click-to-target buttons, all in dependency-free vanilla JS.

Open in Lab
vanilla-js svg
Targets: JS HTML

Code

SVG Path Morph

A compact morphing engine that transitions one SVG shape into the next by interpolating raw path coordinates. Each shape in the set is authored with the same command structure and an equal number of anchor points, so the tween is a straight linear blend between matching coordinate pairs, wrapped in a cubic easing curve and driven by requestAnimationFrame. The result is a fluid liquid-like transformation between a heart, a star, a blob, a gear, and a droplet.

Interaction is front and center. The component autoplays through the shape cycle on a timer, and a play/pause control lets you stop the loop at any point. A row of target buttons lets you jump straight to any shape — the engine morphs from the current interpolated state, not just the last keyframe, so rapid clicks still animate smoothly. A speed slider and an easing selector let you tune the feel, and a live readout shows the morph progress and which pair is currently blending.

The technique demonstrated is point-count-normalized path interpolation: the reliable, library-free way to morph SVG shapes. Because every path shares the same segment layout, the code can walk both coordinate arrays in lockstep and emit a fresh d attribute each frame. It respects prefers-reduced-motion by snapping between shapes instead of animating, keeps the canvas DPR-independent by using vector SVG, and stays fully keyboard-accessible with visible focus states.