Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Add Page Transitions to Astro

Make moving between pages feel smooth with Astro's ClientRouter, or with one line of CSS that needs no JavaScript at all.

Tested on Astro 7.4

Cover image for How to Add Page Transitions to Astro
In this guide
  1. Option 1: One line of CSS, no JavaScript
  2. Option 2: Astro’s ClientRouter
  3. Make an element travel between pages
  4. Change the animation
  5. Which should you use?
  6. Frequently asked questions

By default, clicking a link loads a whole new page, with a flash of white in between. Transitions smooth that over, so your site feels more like an app. Astro gives you two ways to do it.

Option 1: One line of CSS, no JavaScript

Modern browsers can animate between pages on their own. Add this to a stylesheet that every page loads:

@view-transition {
  navigation: auto;
}

That’s it. Pages now cross-fade as you move between them. This is what we use on AstroBeginner, and it adds no JavaScript to the site.

Option 2: Astro’s ClientRouter

For more control, Astro’s ClientRouter component takes over navigation. Add it to your shared layout’s <head>:

---
import { ClientRouter } from 'astro:transitions';
---
<html lang="en">
  <head>
    <ClientRouter />
  </head>
  <body>
    <slot />
  </body>
</html>

Every page using this layout now transitions with a fade. The router also keeps things like a playing video alive between pages, if you ask it to.

Make an element travel between pages

The nicest effect is when one element appears to move from one page to the next, like a post title on a list growing into the heading on the post. Give the element the same transition:name on both pages:

<h1 transition:name="page-title">Welcome to my website</h1>

Each name can only be used once per page.

Change the animation

Use transition:animate to pick a different movement. The options are fade, which is the default, slide, none and initial:

<main transition:animate="slide">
  <slot />
</main>

Which should you use?

Start with the CSS version. It’s a single rule, and it’s enough for most sites. Move to ClientRouter when you need something it can do and CSS can’t, such as keeping an element on the page while the rest changes.

Frequently asked questions

Do page transitions slow my site down?

The CSS-only version adds nothing to your pages. Astro's ClientRouter adds a small script. Neither should make a noticeable difference on a well-built site.

Why don't I see any animation?

Check that the tag is in a layout that both pages share, and that your system isn't set to reduce motion. Browsers skip the animation when that setting is on.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask in the official Astro Discord, where the support channels are friendly to beginners.

Keep reading

  1. How to Deploy an Astro Site to Cloudflare Workers

    Put your Astro site online with Cloudflare Workers in four steps. This is how AstroBeginner itself is hosted, so every step has been run for real.

    Tutorials, 7 minute read, November 6, 2026

  2. How to Add Tailwind CSS to Astro

    Add Tailwind CSS to an Astro site with one command, then style your first element. Tested on Astro 7.4 and Tailwind 4.

    Tutorials, 5 minute read, November 6, 2026

  3. How to Add Images to an Astro Site

    Add an image to your Astro site, and let Astro shrink and convert it automatically. One test image went from 62 kB to 5 kB.

    Tutorials, 6 minute read, November 6, 2026

Try "blog", "deploy" or "EmDash".