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

Click a link on most sites. The whole page reloads. You see a flash of white in between. A page transition smooths that over. Your site then feels more like an app. Astro gives you two ways to do it.

Option 1: One line of CSS, no JavaScript

CSS is the code that styles your pages. Modern browsers can fade between pages on their own. You just have to ask. Add this to a stylesheet that every page loads:

@view-transition {
  navigation: auto;
}

That is it. Pages now cross-fade as you move between them. We use this on Astro Nursery. It adds no JavaScript to the site. JavaScript is the code that makes pages do things.

Option 2: Astro’s ClientRouter

Want more control? Astro’s ClientRouter component takes over page moves. A component is a reusable piece of a page. Add it to the <head> of your shared layout. A layout is the frame that all your pages share.

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

Every page that uses this layout now fades between pages. The router can do more. It can keep a playing video alive from one page to the next, if you ask it to.

Make an element travel between pages

This is the nicest effect. One item seems to move from one page to the next. Think of a post title in a list. It grows into the big heading on the post page. To do it, give the item the same transition:name on both pages:

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

Use each name only once per page.

Change the animation

Use transition:animate to pick a different movement. You have four choices. fade is the default. The others are slide, none and initial:

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

Which should you use?

Start with the CSS version. It is one rule. It is enough for most sites. Move to ClientRouter when you need more. For example, it can keep one item on the page while the rest changes. CSS cannot do that.

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. On a well-built site, you should not notice either one.

Why don't I see any animation?

Check two things. First, the tag must be in a layout that both pages share. Second, your system must not be 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 the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

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