Marcus Andrey Study
Ler em português Library

Motion and Interaction · Step 4 · 6 min read

Shared element transitions

When the photo on a card becomes the photo on the next page, people don't have to look for it. What a shared element is, when Material's container transform fits, how the View Transition API does it in a browser, and how to keep it short, honest and safe for reduced motion.

The best transition is the one where nothing seems to change except the size. You tap a card with a photo of Lisbon. The card grows, the photo stays in view the whole time, and now it's the top of the trip page. You never lost sight of the thing you chose. That's a shared element: one object that exists on both screens, and the motion that carries it across.

What you'll be able to do after reading:

  • Explain what a shared element is and what it does for people
  • Tell when a container transform fits and when it doesn't
  • Sketch it in CSS, and know how the View Transition API does it for real pages
  • Keep it short, and give it a reduced-motion version

1. The card becomes the page

Lisbon, 3 days

Open the Lisbon card, then close it. Keyboard: Tab to it and press Space.

A container transform: the card you pressed becomes the page, so you never wonder where the page came from or where the card went. The container grows in 400 ms; the new content fades in after 150 ms, once there's room for it; closing runs the other way, a little faster, at 300 ms. With reduced motion the page fades in over the card instead of growing out of it.Live CSS, no script: clip-path so the text never stretches. Curve: Material's emphasized easing, cubic-bezier(0.2, 0, 0, 1). Demo: Marcus Andrey, CC BY 4.0.

Open the Lisbon card. What you see is Material's container transform: "the bounding container of a start View" (here, the card) "transforming its size and shape into that of an end View" (the page), while the contents inside "are swapped to create the transition" (Material Components for Android, Motion). Material's examples are a card into a details page, a list item into a details page, a floating action button into a details page, and a search bar into expanded search.

Close it, and it shrinks back into the same card in the same spot. That's the spatial promise from The spatial model of an interface: leave the way you came.


2. Why it helps

A cut asks people to find their place again: where's the thing I tapped? A shared element answers before they ask. NN/g describes this job for animation in general: motion can show "how that element relates to other elements on the page and to any actions that the user has just taken", and works best when it's in the person's focus of attention (NN/g, Animation for Attention and Comprehension, 2014). The card they just tapped is exactly where they're looking.

It's also the most honest transition there is. The page really is "the card, opened". The motion just shows that.


3. When it fits, and when it doesn't

Use a shared element when one thing appears on both screens and people will look for it:

  • A photo, a product, a contact, a file: the item in a list and the same item's page.
  • A search field that grows into the full search screen.
  • A button that becomes the form it opens.

Don't use it when the two screens only look alike, or when several things would fly across at once. Three elements moving in three directions is choreography people have to watch (Choreography and stagger); pick the one that matters, and fade the rest.


4. The code that runs (the sketch)

The figure is a sketch in plain CSS. The page sits on top of the cards, clipped to the size of the Lisbon card; opening it un-clips it. These are the rules that animate, as they run:

.mo-b-ct__detail {
  position: absolute; inset: 0; z-index: 2; background: var(--ground);
  clip-path: inset(8% 52% 32% 6% round 12px); visibility: hidden;
  transition: clip-path 300ms cubic-bezier(0.2, 0, 0, 1), visibility 0s 300ms;
}
.mo-b-ct:has(.mo-b-ct-open:checked) .mo-b-ct__detail { clip-path: inset(0 0 0 0 round 0); visibility: visible; transition: clip-path 400ms cubic-bezier(0.2, 0, 0, 1), visibility 0s; }
.mo-b-ct:has(.mo-b-ct-open:checked) .mo-b-ct__in { opacity: 1; transition: opacity 250ms linear 150ms; }
@media (prefers-reduced-motion: reduce) {
  /* no growing: the page fades in over the card */
  .mo-b-ct__detail { clip-path: none; opacity: 0; transition: opacity 200ms linear, visibility 0s 200ms; }
  .mo-b-ct:has(.mo-b-ct-open:checked) .mo-b-ct__detail { clip-path: none; opacity: 1; transition: opacity 200ms linear, visibility 0s; }
  .mo-b-ct:has(.mo-b-ct-open:checked) .mo-b-ct__in { transition: none; }
}

Two choices to notice:

  • clip-path, not scale. Scaling a page from card size would squash its text in the middle of the motion. Clipping keeps the page at its real size and only reveals more of it. It costs more to draw than transform, so keep it to one element at a time (Motion performance).
  • The content waits. The container grows in 400 ms with Material's emphasized curve, cubic-bezier(0.2, 0, 0, 1) (Material Web, motion tokens). The new text only fades in after 150 ms, once there's room for it to be read. Closing is faster, 300 ms, and the text leaves first.

5. For real pages: the View Transition API

On a real site, the card and the trip page are different pages, and the browser can animate between them. With the View Transition API you give the same view-transition-name to the element on both pages, and the browser morphs one into the other (MDN, View Transition API; MDN, view-transition-name). For navigations between pages of the same site, one at-rule opts both pages in (MDN, @view-transition):

/* on both pages */
@view-transition { navigation: auto; }

/* on the list page */
.trip-card--lisbon img { view-transition-name: lisbon-photo; }
/* on the trip page */
.trip-hero img        { view-transition-name: lisbon-photo; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none; }
}

This one is an example for your own site, not the code of the figure. Each name must be unique on a page, so in a list you set it only on the card that was tapped. Cross-page view transitions work only for same-origin navigations (MDN, @view-transition), and support still differs between browsers: browsers without it simply load the page, which is a fine fallback. The next step covers it in depth (Web Animations and View Transitions).


6. Common mistakes

  • Several elements flying across at once, each on its own path.
  • A shared element between screens that aren't really "the same thing".
  • Scaling a container with text in it, so the text squashes and stretches.
  • Long morphs (over half a second) on something people open all day.
  • No reduced-motion version: a full-screen grow is a large movement.

7. Vocabulary

Term Meaning
Shared element One object that appears on both screens and is carried across
Container transform Material's pattern: a container grows into the next screen while its contents swap
View Transition API The browser feature that animates between two states or pages
view-transition-name The CSS name that tells the browser two elements are the same thing
Cross-fade One image fading out while another fades in, in the same place

8. Try it (no tools needed)

  1. Find three places in your product where an item in a list opens its own page.
  2. For each, name the one element that appears on both screens.
  3. Sketch, in three frames, how it would grow from the list to the page and back.

Reflection questions: Where do people in your product lose their place after opening something? Which element would you carry across first?


9. If you already practise

  • Agree on one shared-element pattern for "item to its page" and use it everywhere, with fixed tokens for duration and curve.
  • Test the back path as carefully as the forward one: the item must land in the same place in the list, even after scrolling.
  • Treat the morph as an enhancement: the page must work and make sense with it off.

Checklist

Learn more

Books, courses and videos to go deeper

Book links go to Amazon. As an Amazon Associate I earn from qualifying purchases, at no extra cost to you.

Navigation transitions · Web Animations and View Transitions · Build a page transition · Choreography and stagger · The spatial model of an interface

Saved only on this device.

↑ ↓ to move · Enter to open · Esc to close