Powerful CSS-only Page Transitions with View Transitions

9.26.2024
by
Web Bae

Learn how to create dynamic and eye-catching page transition animations in Webflow using only CSS and the View Transitions API. We'll take a look at @view-transition css rule, view-transition-name CSS property, and how to make it all work with the Webflow CMS. I used to reach for complex Javascript libraries like Barba.js and GSAP for this but now we can do it easily with a few lines of CSS.

DEMO/CLONE
CODE
TUTORIAL

See the Pen Splide Slider by learyjk (@learyjk) on CodePen.

What Even Is the View Transitions API?

Alright, time to talk about the View Transitions API—a relatively new and shiny tool that lets you animate between pages without dousing your project in JavaScript spaghetti. There is a JavaScript side to this API, but today, we’re staying in the CSS lane. Buckle up and let’s throw this into Webflow step-by-step.

If you were doing this the old-school way, you’d have to pull in a heavy library like Barba.js or wrestle with manually handling state and transitions, which is about as much fun as doing your taxes. But now, the View Transitions API can do all that smooth in-and-out animation work with just a few lines of CSS. No library overhead. No manual DOM sorcery. Just style rules and page magic.

Why Should You Care?

In web dev, “View Transitions” is shorthand for “I don’t want my page jumps to feel like a YouTube ad skip.” This API is designed for both Single-Page Applications (SPAs) and Multi-Page Applications (MPAs). Today, we’re looking at MPAs—basically, any site where clicking a link sends you to an entirely different page, complete with a full page reload. The API’s magic is that it takes that clunky page switch and turns it into a smooth visual experience. No more feeling like someone slapped you across the face with a fresh HTML document.

How to Set It Up in Webflow

Here’s the quick-and-dirty guide to getting this rolling in Webflow:

Step 1: Build the Initial Layout

Start with a basic Webflow CMS Collection. Set it up as a grid displaying blog posts, where each item has an image, a heading, a paragraph, and a “Read More” button. Classic.

Got it? Good. Now let’s move on to making it not suck.

Step 2: Slap in the @view-transition At-Rule

Add this little gem of CSS to your site-wide <head> tag in Webflow’s custom code settings:

<style>
  @view-transition { navigation: auto;}
</style>

Boom, you’ve just unlocked the magic. This one-liner opts your entire site into view transitions, meaning even the most boring, vanilla page navigation will now have a built-in fade effect. When a user clicks from your blog post list to a single post, you’ll get a subtle crossfade instead of the usual jarring page swap. It’s like the difference between gliding through a revolving door and getting kicked out of a moving car. Small effort, big upgrade.

Step 3: Making It Look Like You Know What You’re Doing

Alright, basic fades are cool and all, but let’s throw in some real animation juice by customizing the transitions with CSS keyframes. Drop these into your style tags:

@keyframes move-out {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(-100%);
  }
}

@keyframes move-in {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0%);
  }
}

/* Apply the custom animation to the old and new page states */
::view-transition-old(root) {
  animation: 0.4s ease-out both move-out;
}

::view-transition-new(root) {
  animation: 0.4s ease-in both move-in;
}

What’s going on here? We’re saying, "Hey, old page, scoot up and get out of the way." And for the new page: "Slide in from the bottom like you’ve got something to prove." Result? A nice, smooth vertical page transition that feels intentional, not like your content is getting yanked offstage by a stagehand on a bad day.

Step 4: Animating Specific Elements with view-transition-name

Okay, so basic page transitions are looking slick, but what if you want to get fancy and animate specific elements, like images or headings, between pages? That’s where view-transition-name comes in. This CSS property tells the browser, "Hey, track this element between page loads and animate it like a superstar." We have to tag it with view-transition-name on botht he old and new pages so that the view transition can track it.

Since I am using CMS here and everything that gets the view-transition-name property needs a unique ID, I'm shifting from the Webflow Image element to a custom code embed. We have to use a custom code embed here because Webflow Custom CSS properties don't allow us to inject CMS fields and also reserves the style tag in custom attributes. Here's how the workaround looks in the embed (it's just HTML yo).

<img src="{inject-cms-image-tag-here}" alt="alt-text-by-asset-bae" style="view-transition-name:{inject-cms-slug-here}" />

If we want to animate MORE stuff, it makes sense to reuse the item slug, but the append a unique string depending on the element.

<img src="{inject-cms-image-tag-here}" alt="alt-text-by-asset-bae" style="view-transition-name:{inject-cms-slug-here}-image" />
<h2 style="view-transition-name:{inject-cms-slug-here}-title">{inject-cms-name-tag-here}</h2>
<p style="view-transition-name:{inject-cms-slug-here}-summary">{inject-cms-summary-tag-here}</p>

Browser Support (or Lack Thereof)

One thing to keep in mind: the View Transitions API is not universally supported yet. Safari is the big holdout, which means this is still in “progressive enhancement” territory. It’s like having a shiny new feature that only half your friends can see. But don’t worry—Safari isn’t slacking forever. They’re rolling out support in Safari 18 as part of macOS Sequoia 15. So, if your users are stuck in Apple’s browser waiting room, relief is on the way.

Why This Matters

The big win here is simplicity. Before the View Transitions API, you had to brute-force this kind of page-to-page animation with libraries like Barba.js or Swup.js, both of which require more code than a teenager’s Minecraft server. But now, just a few CSS properties can get the job done—even in a drag-and-drop builder like Webflow. That means less reliance on bulky JS libraries and more time spent, you know, actually building your site.

Final Thoughts: What You’re Gaining

Here’s the quick rundown on why the View Transitions API is worth your time:

  • Smooth Transitions for MPAs: Finally, multi-page sites can look just as polished as their SPA counterparts without tons of custom scripts.
  • Less JavaScript, More CSS: This API hands off a lot of animation work to the browser itself, making your code lighter and easier to maintain.
  • No-Code-Friendly: Even if you’re trapped in Webflow’s no-code land, you can still add these sweet transitions with just a few code embeds.

Want to Get Fancy?

If you’re itching to go deeper, check out my Barba.js series on Patreon. It’s a comprehensive guide to handling custom page transitions and fallback strategies, especially if you need to support Safari right now and can’t wait for Sequoia 15. And if you like this kind of stuff, you'd probably be interested in more CSS only animation or even fancy GSAP stuff if you want to take it to the next level.

So there you have it—View Transitions in a nutshell. Go forth, animate, and stop letting your pages slam around like a broken screen door.