Getting started
Install from npm, add three elements, call useMorph.
react-morphcard is a React hook that grows a card into a detail view and shrinks it back, with the card's title, name and badge flying into the header.
Every card below opens with the library. Click one: it grows into a preview of that page, its icon and title fly into the header, and Back, Esc or a click outside shrinks it back onto the card.
Install from npm, add three elements, call useMorph.
Change duration, easing, stagger and speed, then click the tiles.
Every option of useMorph, what it returns, and the data attributes.
What moves when, with every duration and easing.
Back during an open turns the same animations around.
Reduced motion is opacity only. Focus goes in and comes back.
Seven bugs from a real app, each now a rule and a test.
List to detail with a URL, a photo gallery, a wallet card.
When the browser API is enough and when it is not.
react-morphcard does one transition. You give useMorph three elements (the detail sheet, the content behind it and an optional scrim) and mark the parts that should travel with data-morph. When a card is clicked, it measures both ends and plays the transition with the Web Animations API.
import { useMorph } from "react-morphcard";data-morph="key" on the card and in the sheet flies between the two. Text that wraps differently on each side crossfades while it flies.Desktop and mobile browsers, installed PWAs and WebViews: anywhere React DOM runs. The sheet can be a centred panel, as on this site, or cover the whole screen, as in a phone app. It does not support React Native.




The anatomy page takes this transition apart on a timeline you can scrub, with every duration and easing.
The hook uses Element.animate, animates clip-path: inset() and sets the inert attribute. inert is the newest of these: Chrome and Edge 102, Firefox 112, Safari 15.5 (caniuse). The automated tests run in Chromium only so far.
Version 0.1. The API is small and may still change before 1.0. Install it from npm as shown in Getting started.
Made by Lucas Piera