Back to Explore
THE PLAYGROUND · SCROLL & NAVIGATION

Shared Element Transition

An image moves seamlessly between compact and expanded views.

Shared Element TransitionScroll & Navigation · An image moves seamlessly between compact and expanded views.
CLICK
Dolomite mountain landscapeExplore the mountains
01 / LANDSCAPESA little escape.
CLICK TO REPLAY · 600 ms
1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function SharedDemo() {7  const [open, setOpen] = useState(false);8  return <motion.div layout style={{...surface, width: open ? 320 : 150, height: open ? 240 : 110, overflow: "hidden", cursor: "pointer"}} transition={{ duration: 0.6, delay: 0, ease: "easeInOut" }} onClick={() => setOpen(v => !v)} role="button" tabIndex={0} onKeyDown={e => {if(e.key === "Enter") setOpen(v => !v);}}>9    <motion.div layout style={{width: "100%", height: "80%", background: "#71c7be"}}>Your image</motion.div>10    <motion.span layout>{open ? "Close detail" : "Open detail"}</motion.span>11  </motion.div>;12}

Install: npm install motion. A shared layout identity connects the two states. This compact example illustrates the core technique; the styled playground contains additional presentation details.