Meet the View Transitions API by kirupa (https://www.kirupa.com/me/index.htm) | filed under Web Animation (https://www.kirupa.com/html5/learn_animation.htm) TL;DR: The View Transitions API animates between two states of a page. We pass our DOM update to document.startViewTransition, and the browser takes a picture of the old view, runs our update, and crossfades to the new view. Elements that share a view-transition-name fly between their spots, and the @view-transition rule animates between pages. - The old view is a still picture and the new view stays live, and we style both through the ::view-transition-old and ::view-transition-new pseudo-elements. - Only one element can have a given view-transition-name at a time, so a duplicate name skips the animation while our update still runs. - Animating between pages takes the @view-transition rule on both pages, and it only works for pages on the same origin. - Checking for document.startViewTransition before using it means browsers without support still update the page, just without the animation. Changing what's on a web page is instant. We click a thumbnail, some JavaScript swaps a grid of items for a detail view, and the old view is simply gone. That's great for speed, but it can feel abrupt, and it's easy to lose track of where the thing we clicked went. Animating from one view to the other used to mean cloning elements, measuring where they were and where they ended up, and carefully moving copies around with a lot of fiddly code. These days, the browser can do most of that work for us. In this article, we'll look at how to animate between two states of a page with very little code, how to make an element fly from one spot to another, and how to animate between two separate pages. Here's what we'll be working toward. Click a fruit, then go back: Live demo: A grid of six fruit. Clicking one animates its icon and name into a larger detail view, and the Back button animates it back (https://www.kirupa.com/animations/examples/view_transitions_gallery.htm) Onwards! What Happens When We Start a View Transition? Let's say we have a function that updates the page, like replacing the fruit grid with the grapes' detail view. Normally, we'd just call it. To animate the change instead, we hand that function to the browser and let the browser decide when to call it: document.startViewTransition(() => { showDetail(grapes); }); That one call is the heart of the View Transitions API. Behind the scenes, the browser goes through four steps: [Image: Four steps. 1: the browser takes a picture of the old view. 2: it runs our update function while the screen keeps showing that picture. 3: it captures the new view. 4: it animates from the old picture to the new view, with a crossfade by default.] (https://www.kirupa.com/animations/images/vt_steps.png) Here's what happens in each one: 1. The browser takes a picture (a snapshot) of the page as it looks right now. 2. It calls our function. While our function changes the DOM, the browser stops drawing new frames, so the screen keeps showing the old picture and nobody sees the page in a half-updated state. 3. Once our function is done, the browser captures the new state of the page. 4. It animates from the old picture to the new view. By default, that's a crossfade, where the old picture fades out while the new view fades in, over a quarter of a second. Because the screen holds still during step 2, our update function should be quick. It can be an async function that waits on something, but the page looks frozen until it finishes. If our update needs to fetch data, it's better to fetch it first and only start the transition once we have everything we need. The startViewTransition method returns a ViewTransition object with a few promises on it. The ready promise resolves when the animation is about to start, finished resolves when it's done and the new view is fully interactive, and updateCallbackDone resolves when our function finishes. There's also a skipTransition method that jumps straight to the end. We won't need these for most transitions, but they're handy when we want to run code at a specific moment, like moving focus after the animation ends. What Are the ::view-transition Pseudo-Elements? The animation in step 4 isn't happening on our real elements. While a transition runs, the browser builds a small tree of pseudo-elements on top of the whole page and animates those instead. Pseudo-elements are things we can style with CSS even though they don't appear in our HTML, like ::before and ::after. Here's the tree the browser builds for our fruit gallery: [Image: ::view-transition sits on top of the page. Inside it is a ::view-transition-group for root and one for fruit-icon. The fruit-icon group holds a ::view-transition-image-pair, which holds ::view-transition-old (a picture of the old view) and ::view-transition-new (the live new view).] (https://www.kirupa.com/animations/images/vt_pseudo_tree.png) At the top is ::view-transition, an overlay that sits above everything else on the page. Inside it, each thing that transitions gets its own ::view-transition-group. By default, there's just one, called root, which holds the whole page. That's why a plain transition crossfades everything at once. A group animates its position and size, and inside each group, an image pair holds the two pictures that get crossfaded: ::view-transition-old is the picture of the old view, and ::view-transition-new is the new view, which stays live while it animates. The neat thing is that these are all regular CSS animations, so we can change them with regular CSS. For example, this slows every group down a little and gives it a friendlier easing curve: ::view-transition-group(*) { animation-duration: 0.4s; animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); } The * matches every group. Setting the duration on the groups is the safe choice, because the image pair and the old and new pictures inside a group inherit it, so everything stays in sync. To see these pseudo-elements in action, turn on Slow motion in the demo. All it does is add a class that stretches the duration to 2 seconds. How Do We Morph One Element Into Another? A crossfade of the whole page is nice, but the real fun starts when one element flies from its old spot to its new spot. In our gallery, the grapes icon starts as a small picture in a grid card and ends up as a big picture on the left of the detail view. They're different elements in the DOM, but to us they're the same grapes, so we'd like them to move and grow from one place to the other. To make that happen, we give the old element and the new element the same name, using the view-transition-name CSS property. When the browser sees an element with a name in the old picture and an element with the same name in the new view, it pulls them out of the root group and gives them a group of their own: [Image: The grapes icon has view-transition-name: fruit-icon in both views. In the old view it's a 56 by 56 picture in a grid card. In the new view it's 160 by 160 on the left of the detail view. Its group animates the position and size from one to the other while the old and new pictures crossfade.] (https://www.kirupa.com/animations/images/vt_shared_element.png) The fruit-icon group starts at the size and spot of the small icon, 56 by 56 pixels inside its card, and animates to the size and spot of the big one, 160 by 160 pixels. While the group moves, the old and new pictures inside it crossfade. Everything else on the page is still in the root group, so the rest of the page crossfades behind it like before. When an element is always there, we can set its name in our stylesheet: .detail img { view-transition-name: fruit-icon; } In our gallery, though, only the card we click should get the name, so we set it from JavaScript right before starting the transition. Inside the update function, we give the same name to the detail view's icon: card.querySelector("img").style.viewTransitionName = "fruit-icon"; document.startViewTransition(() => { showDetail(fruit); stage.querySelector(".detail img").style.viewTransitionName = "fruit-icon"; }); The demo does the same thing for the fruit's name, using a second name called fruit-name, so the label flies over and grows too. Because the snapshots are pictures, a label that changes size gets scaled like an image. If the old and new boxes have different shapes, the text gets squished or stretched along the way. Giving both labels width: fit-content keeps their boxes the same shape as the text, so the scaling looks natural. Names Have to Be Unique There's one rule that trips up just about everyone at least once. At the moment the browser takes a snapshot, only one rendered element can have a given name: [Image: Two cards both have view-transition-name: hero at the same time. The browser can't tell which one to animate, so it skips the transition. Our update still runs, and the page just changes instantly.] (https://www.kirupa.com/animations/images/vt_duplicate_names.png) If two elements share a name, the browser has no idea which one to animate, so it skips the transition. Our update function still runs, so nothing breaks, but the page changes instantly. In Chrome, the console shows an "Unexpected duplicate view-transition-name" error, which is a big clue. This is why the demo clears the names from the previous transition before setting new ones. Otherwise, after we view the apple and go back, the apple's card would still be named fruit-icon when we click the grapes. For elements that stay in the DOM and just move around, like items in a list that gets re-sorted, giving each one a unique name by hand gets tedious. The match-element value takes care of that for us. Setting view-transition-name: match-element gives every matching element its own automatic name, based on which element it is. How Do We Customize the Animation? A crossfade isn't our only option. Since ::view-transition-old and ::view-transition-new are pseudo-elements, we can give them any CSS animation we like. Here, the old view slides out to the left while the new view slides in from the right: @keyframes slide-out { to { opacity: 0; transform: translateX(-60px); } } @keyframes slide-in { from { opacity: 0; transform: translateX(60px); } } ::view-transition-old(root) { animation: 0.3s ease-in both slide-out; } ::view-transition-new(root) { animation: 0.3s ease-out both slide-in; } Inside the parentheses goes the name of the group we're styling, so root here means the whole page. To style just our flying icon, we'd use fruit-icon instead. When lots of elements should share the same animation, we can give each of them a view-transition-class as well as its unique name, and then target the class with selectors like ::view-transition-group(*.card). A slide like this usually depends on direction. Going forward should slide left, and going back should slide right. For that, we can pass types when we start the transition and check for them in CSS: document.startViewTransition({ update: () => showGrid(), types: ["backward"] }); html:active-view-transition-type(backward)::view-transition-new(root) { animation-name: slide-in-from-left; } The :active-view-transition-type() selector only matches while a transition with that type is running, so the rest of the time, our styles stay out of the way. Can We Animate Between Two Pages? So far, everything has happened on a single page, with JavaScript changing the DOM. The same kind of animation also works when we click a link and the browser loads a whole new page. These are called cross-document view transitions, and we don't need any JavaScript for them. Both pages just opt in with a bit of CSS: @view-transition { navigation: auto; } When we click a link from one opted-in page to another, the browser takes a picture of the old page, loads the new one, and animates between them: [Image: Two browser windows on the same site. Page one lists a cookie. Clicking its link loads page two, which shows the cookie much bigger. Both pages opt in with the @view-transition rule, so the browser animates between them.] (https://www.kirupa.com/animations/images/vt_mpa.png) Everything we've seen so far still applies. The new page gets the same tree of pseudo-elements, and if the cookie on the first page and the big cookie on the second page share a view-transition-name, the cookie flies from one page to the other. You can try it with our two-page cookie demo (https://www.kirupa.com/animations/examples/view_transitions_page_one.htm), which opens in a new tab. There are a few rules for this to work: - Both pages have to be on the same origin, which means the same protocol, domain, and port. Going from one page on our site to another works. Going to a different site, or even a different subdomain of ours, doesn't. - Both pages need the @view-transition rule. - It only kicks in for navigations that happen inside the page, like clicking a link or going back and forward. Typing a URL in the address bar, using a bookmark, or reloading won't animate. - The new page has to show up reasonably quickly. Chrome skips the transition if the navigation takes longer than 4 seconds. For finer control, the old page gets a pageswap event right before it's replaced, and the new page gets a pagereveal event right before it's first drawn. Both events have a viewTransition property we can use to set names or types based on where we're coming from and where we're going. Which Browsers Support View Transitions? Same-page view transitions work in every major browser now. Cross-document view transitions are almost there. Here's where things stand as of November 26, 2026: Feature | Chrome and Edge | Safari | Firefox startViewTransition (same page) | 111 | 18.0 | 144 view-transition-class | 125 | 18.2 | 144 Transition types | 125 | 18.2 | 147 @view-transition (between pages) | 126 | 18.2 | Coming in 162 Same-page view transitions became Baseline in October 2025, when Firefox 144 shipped them. For cross-document transitions, Firefox has them turned on by default in version 162, which is scheduled to ship on December 8, 2026. The current details live on MDN's View Transition API (https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) page and in Chrome's view transitions docs (https://developer.chrome.com/docs/web-platform/view-transitions). Even with great support, some people will be on older browsers, so it's worth making sure our code still works without the API. For same-page transitions, we check whether the method exists before using it: function update(change) { if (!document.startViewTransition) { change(); return; } document.startViewTransition(change); } In a browser without view transitions, the page still updates. It just doesn't animate. Cross-document transitions need even less work, since a browser that doesn't understand the @view-transition rule ignores it, and links keep working like regular links. A view transition is a nice extra on top of a page that already works, which is exactly how it should be. What About People Who Prefer Less Motion? Some people get dizzy or even sick from things flying across the screen, so they turn on a reduced motion setting on their device. Browsers expose that setting through the prefers-reduced-motion media query, and our view transitions should listen to it. For cross-document transitions, the simplest approach is to only opt in when the person hasn't asked for less motion: @media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } } For same-page transitions, reduced motion doesn't have to mean no animation at all. A short crossfade still helps people follow what changed, without anything zooming around. That's what our gallery does. When your device asks for less motion, it skips the view-transition-name values, so the icons don't fly, and you get the default crossfade instead. We go much deeper into this in Respecting Reduced Motion (https://www.kirupa.com/animations/respecting_reduced_motion.htm). What Gotchas Should We Watch Out For? View transitions are easy to start using, but a few details can catch us off guard. Here are the ones that tend to come up: - Only one rendered element can have a given view-transition-name at a time. Duplicate names skip the transition, so clear old names before setting new ones. - The screen freezes while our update function runs. Keep it fast, and do slow work like fetching data before starting the transition. - Snapshots are pictures. A snapshot that changes shape gets stretched like an image, which can distort text, so try to keep the old and new boxes the same shape. - While a transition runs, ::view-transition covers the page, so clicks during the animation don't reach our elements. Short durations keep this from being noticeable, and Bramus Van Damme has a good write-up (https://www.bram.us/2025/01/29/view-transitions-page-interactivity/) on letting clicks pass through when it matters. - Only one transition runs at a time. Starting a new one skips the one in progress, and a transition started while the page is hidden is skipped right away. Either way, our update still runs. Conclusion The View Transitions API flips how we think about animating between views. Instead of moving our real elements around ourselves, we let the browser take a picture of the old view, run our update, and animate between the picture and the new view. Out of the box, that gives us a crossfade with one line of JavaScript. Naming elements with view-transition-name lets them fly from one spot to another, the pseudo-elements let us swap in any animation CSS can do, and the @view-transition rule brings all of it to plain links between pages. Best of all, it's a feature that fails gracefully. Browsers that don't support it still update the page, and people who prefer less motion can get a gentle fade instead of a flight. Before you go, here are a few things you can do: 1. Test your knowledge by taking the quiz below. 2. Read the next article in the series, Animating Drop Shadows (https://www.kirupa.com/animations/animating_drop_shadows.htm), or check out some related content: - Respecting Reduced Motion (https://www.kirupa.com/animations/respecting_reduced_motion.htm). Tone down motion for people who ask their device for less of it. - Creating a Morph Animation Without Actually Morphing (https://www.kirupa.com/html5/creating_morph_animation_without_morphing.htm). Fake a morph between shapes with border-radius, clip-path, and crossfades. - Customizing CSS Animations (https://www.kirupa.com/animations/customizing_css_animations.htm). Fine-tune CSS animations with keyframes, timing, and more. 3. Stuck on something, or curious about a detail we skipped? Ask on the forums (https://forum.kirupa.com/), and we'll help you out. [Mastery Quiz] Test your knowledge! Take the The View Transitions API Quiz: https://www.kirupa.com/quizzes/view_transitions_api.htm Practice with 8 multiple-choice questions and an explanation after every answer. [/Mastery Quiz]