LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. State transitions

Shared element transition

Also called hero animation, magic move, or shared layout animation

A transition where an element from one view, like a thumbnail, travels and grows into its place in the next view, linking the two screens.

import { useState } from 'react';
import { Dialog } from '@base-ui/react/dialog';
import { AnimatePresence, motion } from 'motion/react';

const photos = [
  { id: 'harbor', title: 'Harbor at dawn' },
  { id: 'dunes', title: 'Desert dunes' },
  { id: 'lagoon', title: 'Glacier lagoon' }
];
type Photo = (typeof photos)[number];

// The thumbnail and the large image share a layoutId, so Motion flies one into the other.
function PhotoImage({ photo }: { photo: Photo }) {
  return (
    <motion.img
      layoutId={photo.id}
      layoutCrossfade={false}
      transition={{ type: 'spring', bounce: 0, duration: 0.4 }}
      src={`/photos/${photo.id}.jpg`}
      alt={photo.title}
      style={{ borderRadius: 12 }}
      className='aspect-square w-full object-cover'
    />
  );
}

export function PhotoGallery() {
  const [open, setOpen] = useState<Photo | null>(null);
  return (
    <Dialog.Root open={open !== null} onOpenChange={() => setOpen(null)}>
      <div className='grid w-96 grid-cols-3 gap-3'>
        {photos.map((photo) => (
          <button key={photo.id} type='button' onClick={() => setOpen(photo)}>
            <PhotoImage photo={photo} />
          </button>
        ))}
      </div>
      <AnimatePresence>
        {open && (
          <Dialog.Portal keepMounted>
            <Dialog.Backdrop className='fixed inset-0 bg-black/40 transition-opacity duration-300 data-ending-style:opacity-0 data-starting-style:opacity-0' />
            {/* The exit fade also tells Base UI to wait before hiding the popup. */}
            <Dialog.Popup
              render={<motion.div exit={{ opacity: 0 }} />}
              className='fixed top-1/2 left-1/2 w-80 max-w-[calc(100vw-2rem)] -translate-1/2'
            >
              <PhotoImage photo={open} />
              <div className='mt-2 flex items-center justify-between rounded-xl bg-background p-4 transition-[opacity,translate] duration-300 starting:translate-y-2 starting:opacity-0'>
                <Dialog.Title className='font-medium'>
                  {open.title}
                </Dialog.Title>
                <Dialog.Close className='text-sm underline'>Close</Dialog.Close>
              </div>
            </Dialog.Popup>
          </Dialog.Portal>
        )}
      </AnimatePresence>
    </Dialog.Root>
  );
}
In the photo grid, when a thumbnail is clicked, expand it into a detail card with a shared element transition: the image grows from its grid position to the top of the card over about 400ms with a spring (no bounce) while the card text fades in. Closing with the close button, the Escape key, or a click outside should shrink the image back into its tile. Use Motion’s layoutId for the image and the title.

Paste into Layerwise or any AI coding tool.

What is Shared element transition?

In a shared element transition, the same item appears on two screens, and the change between them animates that item from its old position and size to its new one. Tap a photo in a grid and it expands into the large photo on the detail view; close it and it shrinks back into its tile. The rest of the screen usually fades around it.

It helps people keep their place, because they can see where the detail view came from and where it will return. It is common in photo galleries, product grids, music apps, and any list that opens into a detail view. Flutter calls it a Hero animation, and Keynote calls a similar effect Magic Move.

On the web, Motion does this with layoutId: give the thumbnail and the detail image the same ID, and Motion animates between them when one replaces the other. The browser’s View Transitions API does the same with view-transition-name. Keep it around 300 to 500ms, and make sure closing lands the element exactly back in its tile.

Often confused with

Morph
A morph reshapes one element in place. A shared element transition carries an element from one view to another.

Related terms

All terms

Layout animation

An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.

View Transitions API

A browser feature that animates between two states of a page by snapshotting the old view, applying your update, and animating to the new one.

Page transition

An animation that plays when you move from one page or screen to another, such as the old page fading out as the new one fades in.

Spatial consistency

Moving elements in ways that match where things live in the interface, so people can tell where an item went and how to find it again.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit