Skip to content
Quillyst
All posts

View transitions without a framework

Native page transitions are here. A walkthrough of the API and how Astro makes it a one-liner.

Ava Thompson1 min read

Smooth transitions between pages used to be the exclusive territory of single-page apps. The View Transitions API brings them to plain multi-page sites, and Astro wraps it in a single component.

Turning it on

Add the client router to your document head:

---
import { ClientRouter } from 'astro:transitions';
---

<head>
  <ClientRouter />
</head>

Navigation now cross-fades by default, and the browser keeps scroll position and focus behaviour sensible.

Shared elements

Give the same element a matching transition:name on two pages, and the browser morphs one into the other — a card’s image growing into an article’s hero, for example.

<img src={cover} transition:name={`cover-${slug}`} alt="" />

Names must be unique on each page, so derive them from something stable like the post slug.

Things to watch for

Scripts run once

Module scripts don’t re-run after a client-side navigation. Re-initialise per-page behaviour by listening for the astro:page-load event, or use event delegation on document.

Respect reduced motion

Some readers find motion uncomfortable. Honour prefers-reduced-motion by shortening or disabling animations.

Worth it?

For content sites, yes. The cost is a few kilobytes, and the result feels noticeably more polished — without giving up the simplicity of real pages.

Related

Keep reading

View all posts

Type to search across all articles.