← Back to CSS
52

View Transitions: animated changes between states

Learn how the View Transitions API lets the browser animate between one interface state and the next, so you can create page changes and UI swaps that feel polished without building the whole effect manually.

📘 Theory

Understanding the transition tree

The browser creates temporary pseudo-elements that represent the old and new states.

1

When you call `document.startViewTransition()`, the browser builds a special layer for the transition. Two of the most important pieces are `::view-transition-old(root)` and `::view-transition-new(root)`.

2

The first one is the visual snapshot of the previous state. The second one represents the incoming state. By default they cross-fade, but you can replace that motion with your own keyframes.

Customizing the transition instead of accepting the default

This is where the API becomes truly useful for interface design.

1

You can assign different animations to the outgoing and incoming pseudo-elements. A slide, a scale, a push or a softer layered motion can all be expressed with normal CSS animations.

2

For more precise continuity, assign `view-transition-name` to a specific element such as a thumbnail, avatar or hero image. That element can then transition independently from the rest of the page.

🧪 Learn by doing

Example Demo: custom slide transition Click the button to simulate a page change and see the old view slide away while the new one enters.

🏁 Challenges

Challenge Challenge: slow down the exit motion The client wants a more dramatic exit. Set the outgoing transition to last 2 seconds.

🧰 Resources

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com