Skip to content

Morph

Morph any SVG into another without the spikes: icons, filled shapes, words, one shape into several.

v1.0.3MITGitHubnpm
npm install @cesarvenzac/morph
Lucide's star to an SVG heart
One drawing through every kind of source Morph takes: a Lucide icon, SVG markup with its paint, a word set in Inter. The heart breaks into the word's letters, and they merge into the sun.

Morph turns one SVG drawing into another: icons, filled shapes in their colours, words set in a font, one shape into several. Most morphs look generated, for the same few reasons: points paired by accident, moved in straight lines, corners snapping in. Morph pairs shapes by what they look like, moves each one whole, rounds it halfway and draws it as a few smooth curves, so every frame between two drawings looks drawn.

Use

import { MorphIcon } from "@cesarvenzac/morph/react";
import { Menu, X } from "lucide";

<button
  onClick={() => setOpen(!open)}
  aria-label={open ? "Close menu" : "Open menu"}
>
  <MorphIcon icon={open ? X : Menu} />
</button>;

Or draw any moment yourself:

import { morph, svg } from "@cesarvenzac/morph";

const m = morph(svg(heart), svg(star)); // matched once
m.at(0.5); // the frame halfway, a path a part

What it does

  • Any SVG, either side. Lucide's icons as they are, any markup, words set in a font, drawings made by hand; the two needn't match.
  • Shapes paired by shape. Pieces pair by what they look like as well as where they are, and holes open and close where they should.
  • More shapes on one side. One shape splits into several, or several merge into one, rather than popping in.
  • Paint that mixes. Colours mix in OKLab as CSS's color-mix() does, widths and opacity follow, and a stroke can fill in.
  • Plays like an interface. A spring that turns back from where it is when it's sent back mid-way: MorphIcon in React, mount in the page, motion anywhere.
  • Small and plain. TypeScript with no dependencies, its core needing no browser: a frame is path data, for an <svg>, a canvas or a server.

How it works, measured, is in Morphs without spikes, and the three ways side by side in Icon morphs. The examples use Lucide's icons.

In use on Brume, where every icon that changes is a morph: a call to action turning into what comes next, a download into a tick.

Docs