Opting pages into a cross-document transition
The View Transition API has a reputation for impressive demos that quickly disappear into JavaScript, which makes the lighter examples more useful for building up familiarity. One practical entry point, popularized by Dave Rupert and Jim Nielsen, is animating a post title from an archive listing into the single post page.
Both the page being left (the "old" page) and the page being navigated to (the "new" page) opt in with the small @view-transition snippet, so no keyframes are strictly required — the default transition handles the animation and @keyframes remain optional.
@view-transition {
navigation: auto;
}
Naming the elements that move
The title on the old page and the title on the new page must share a view-transition-name. Given markup like this:
<h1 class="post-title">Notes</h1>
<a class="post-link" href="https://css-tricks.com/link-to-post"></a>
the pair is matched in CSS:
.post-title { view-transition-name: post-title; }
.post-link { view-transition-name: post-title; }
Respecting reduced-motion preferences just means applying the effect only where the user's system settings permit motion:
@media not (prefers-reduced-motion: reduce) {
.post-title { view-transition-name: post-title; }
.post-link { view-transition-name: post-title; }
}
The problem with lists
A single title pair works fine. A list of post links does not: every link needs its own unique view-transition-name, and new posts are published continuously, so hand-editing CSS for each one is not viable. Chrome is working on an upgrade to the attr() function, described by Bramus, that would generate a series of unique identifiers in a single declaration:
<style>
.card[id] {
view-transition-name: attr(id type(<custom-ident>), none); /* card-1, card-2, card-3, … */
view-transition-class: card;
}
</style>
<div class="cards">
<div class="card" id="card-1"></div>
<div class="card" id="card-2"></div>
<div class="card" id="card-3"></div>
<div class="card" id="card-4"></div>
</div>
That is not standard yet, and adoption by other browsers is still pending, so for now the fallback is programmatic logic in the template. On a WordPress site with PHP available, the name can be generated inline from the post's ID in both the post template (single.php) and the archive template (archive.php):
<?php the_title(
'<h1 class="post-single__title" style="view-transition-name: post-' . get_the_id() . '">', '</h1>'
); ?>
The archive side follows the same pattern:
<?php the_title(
'<h2 class="post-link><a href="' . esc_url( get_permalink() ) .'" rel="bookmark" style="view-transition-name: post-' . get_the_id() . '">', '</a></h2>'
); ?>
Dropping a <style> tag with the logic inside is an alternative, but both approaches are equally awkward next to what attr() promises. Either way, once the shared name and the @view-transition opt-in are in place, the transition runs.
A smaller example: radio inputs
A related sprinkle, spotted in Modern Web Weekly, applies view transitions to radio inputs. It needs JavaScript to suppress the radio's default clicking behavior so the transition can play before the input becomes checked.



