This site is a set of separate HTML pages, not a single-page app. That keeps it fast and simple, and it used to mean every link was a hard cut: one page gone, the next one painted. On a site that animates almost everything inside a page, the moment between pages was the one place with no motion at all.
Cross-document view transitions fix that in CSS. No router, no JavaScript. Getting the basic cross-fade is a few lines; making it behave took three more fixes, and those are the useful part.
The opt-in
Both pages have to opt in, and they have to be same-origin. Because every page here loads the same stylesheet, one rule covers the site:
@media (prefers-reduced-motion: no-preference) {
@view-transition {
navigation: auto;
}
::view-transition-group(*) {
animation-duration: 200ms;
}
}The media query matters: this runs on every navigation, so it belongs behind the same reduced-motion gate as everything else. The duration is shortened from the default because a transition that runs on every click should never make a page feel slower than no transition would.
Browsers that do not support it ignore the at-rule and navigate exactly as before. Chromium supports it from version 126 and Safari from 18.2; Firefox support was still arriving when this was written, so check current support rather than trusting a version number here.
Morphing one element into another
A plain cross-fade is pleasant. The effect people notice is when the thing you clicked appears to turn into the thing you arrive at. That is done by giving both elements the same view-transition-name.
Here, a post's title on an index card and the heading on the post itself both carry post-<slug>, set inline from the post's data. Click a card and its title grows into the article heading while the rest of the page cross-fades.
Fix one: names must be unique on a page
If two elements on the same page share a view-transition-name, the browser cannot decide which one to animate, so it skips the transition for that navigation. No error appears; the page just cuts again.
That is easy to cause by accident — a "related posts" block that happens to include the post you are on, or a "latest" strip that repeats an item already in the main list. Since every page here is rendered at build time, the build now checks each page for a repeated name and warns. It costs a few lines and catches the bug before it ships rather than after someone wonders why one page never animates.
Fix two: named elements ignore your stacking
During the transition, each named element is lifted out of the page and drawn as its own layer above the snapshot of everything else. That layer does not respect the stacking you set up on the page.
The visible result here: scroll the article index so a card title sits under the sticky navigation bar, click it, and for the length of the transition that title is drawn on top of the nav instead of behind it.
The fix is to give the nav a name too. It then becomes its own layer as well, and layers are drawn in the page's paint order, which puts the sticky header back on top. One line, on the header.
Fix three: keep it short and keep it optional
Long, elaborate page transitions are fun to build and tiring to use. Readers on a content site click a lot; 200ms is enough to connect two pages without making anyone wait for it. And reduced motion turns the whole thing off, which for a purely decorative effect is the right default.
What it cost
About twenty lines of CSS, four inline style attributes and a small build check. Nothing ships to the browser that was not already there, and a multi-page site that used to cut between pages now moves between them.
For a long time this was the strongest practical argument for building a content site as a single-page app. It is now mostly gone, and the multi-page version keeps everything it was already good at.