An Underline That Survives a Page Load
How the header underline glides between separate pages with cross-document view transitions, shown in slow motion, plus five lessons from getting it right.
On a wide screen, look up at this page’s header. There is a short gradient line under Notes. Click Projects and the line does not blink out and reappear: it slides over, stretching to fit the longer word, as if the two pages were one.
They are not one page. Every click on this site loads a brand-new HTML document. No client-side router keeps the header alive between pages. The underline crosses that gap with cross-document view transitions, a few dozen lines of CSS, and one changed line of JavaScript.
It also took five lessons to get right. Most of them came from breaking it.
Watch It in Slow Motion
Here is a working model of the header. It uses the site’s real timing: 230 milliseconds on an emphasized ease-out curve. That is too quick to study at full speed, so it starts at a quarter speed. Pick a section, slow it down further, or drag Scrub to step through the last move by hand.
Your system asks for reduced motion, so moves jump straight to the end. Drag Scrub to step through one at your own pace.
Turn on Show what the browser animates to see the moving parts. When you click a link, the browser photographs every element that has a view-transition-name on the old page. Then it loads the new page and looks for an element with the same name. If it finds one, it creates a stand-in, the group, and animates that from the old box to the new one. The real underline on the new page stays hidden until the group lands.
Getting that match takes very little code:
@view-transition {
navigation: auto;
}
.site-nav-link--current::after {
view-transition-name: site-nav-current;
}
::view-transition-group(site-nav-current) {
animation-duration: var(--duration-section-in); /* 230ms */
animation-timing-function: var(--ease-emphasized);
}
Every page marks its current link with the same class, so the underline on the old page and the one on the new page share a name. That shared name is the whole trick. The browser sees one object that moved, not two different underlines.
The Real Thing, Frame by Frame
The demo is a model. This is the real transition. The site’s header was frozen at six moments while going from Notes to Projects in Chromium:

The live Notes → Projects transition, paused with the Web Animations API and captured in Chromium.
Look at how quickly it leaves. Sampling the group once per frame at full speed shows where all of the motion happens:
13 ms x 822.0 px width 43.4 px ← still under Notes
27 ms x 903.4 px width 49.3 px
44 ms x 955.2 px width 53.0 px
61 ms x 986.0 px width 55.3 px
94 ms x 1015.4 px width 57.4 px
127 ms x 1026.4 px width 58.2 px
177 ms x 1031.3 px width 58.5 px
226 ms x 1032.0 px width 58.6 px ← settled under Projects
About two-thirds of the trip is done by 44 milliseconds, and nine-tenths by 94. The last 130 milliseconds move the bar fewer than 20 pixels. That front-loaded curve is why 230 milliseconds feels quick instead of floaty. The bar reacts at once and then settles.
Lesson One: One Bar, Not Two
Left to its defaults, the browser does not move one bar. It cross-fades two pictures inside the group: a snapshot of the old underline fading out and a snapshot of the new one fading in. Each snapshot also keeps its own proportions as the group stretches. The old underline gets thicker as it widens, the new one starts thin, and while both are half transparent the gradient dims.
On a 2-pixel line, all of that reads as a flicker. Slow it down and you can see it:
Your system asks for reduced motion, so moves jump straight to the end. Drag Scrub to step through one at your own pace.
The fix is to choose one snapshot and let it fill the group:
::view-transition-old(site-nav-current) {
animation: none;
opacity: 0;
}
::view-transition-new(site-nav-current) {
block-size: 100%;
animation: none;
}
The old picture is hidden. The new picture is stretched to the group’s height, so the bar stays exactly 2 pixels tall while only its width changes. Lesson: browser defaults assume two different pictures. When the thing in motion is really one object, make it one picture.
Lesson Two: Write the Rule, Then the Exception
Not every page has a current link. Home, the Colophon, and anything else outside the six sections have no underline at all. Then the browser has only one snapshot: the old one when you leave a section, or the new one when you arrive. In that case the snapshot is the :only-child of its group, and the bar should fade in place.
My first draft scoped the hiding rule with :not(:only-child), so it would apply only when both snapshots existed. Chromium did not apply it. What worked was the plainer arrangement: a base rule for the usual case, then a positive :only-child override for the exception:
::view-transition-old(site-nav-current):only-child {
animation: site-nav-current-out var(--duration-section-out) ease both;
}
::view-transition-new(site-nav-current):only-child {
animation: site-nav-current-in var(--duration-section-in) ease both;
}
You can see both fades in the first demo by visiting Home and coming back. Lesson: view-transition pseudo-elements are new territory for selector support. Write the common case as a base rule, and test the exception in every engine instead of trusting a clever selector.
Lesson Three: Don’t Move What the Browser Captured
This one took the longest to find. Sometimes the bar did not glide. Sometimes the whole page transition, fade and all, just snapped to the end.
The cause was the navigation script. On narrow screens it tucks some links into a More menu. When the layout is wide, it put the full list back with replaceChildren, and it did that every time it checked, even when no link had ever moved. Putting an element back into the list removes it and inserts it again. If the browser has captured that element for a transition, that brief removal ends the entire transition early. It does not just stop the bar.
Your system asks for reduced motion, so moves jump straight to the end.
The fix was one condition. Restore the full list only if it was actually split up:
if (compact.matches) {
overflowList.replaceChildren(...overflow);
list.replaceChildren(...primary, more);
} else if (more.isConnected) {
// Restore the full list only after a compact layout: re-inserting links
// that never moved would end a page transition that captured one of them.
list.replaceChildren(...items);
}
Below the medium breakpoint, the links really do get regrouped. There, the bar gives up its name until the script has finished, so there is nothing to interrupt. Bugs like this live in timing, so they show up only now and then. To catch it every time, I rewrote the page in the test browser to put a deliberately slow script right after the header. That made the navigation code run mid-transition on every load.
Lesson: a named element has to stay put for the length of the transition. Check your own scripts before blaming the browser.
On wide screens the header fades away as you scroll down and comes back when you scroll up. Hidden, I assumed, meant out of the picture.
It doesn’t. The browser captures a named element wherever it is, even above the top of the window. It also captures the element without its ancestors’ opacity, so a faded-out header still gives you a full-strength bar. Leave a page you have scrolled down, and the underline comes flying in from above the viewport. That happens more often than you might think. The link at the end of this note is a link in the page, clicked while the header is hidden.
Your system asks for reduced motion, so moves jump straight to the end. Drag Scrub to step through one at your own pace.
The fix is to give up the name whenever the header is not showing:
@media (width >= 64rem) {
html[data-site-header="h"] .site-nav-link--current::after {
view-transition-name: none;
}
}
With no name on the old page, there is nothing to travel from, so the :only-child fade from Lesson Two takes over. The header gets the same treatment. Its group has animation: none, so it holds the new header’s position from the first frame instead of sliding in from wherever the old one sat. Lesson: if an element is not visible, decide what that means for the transition. The browser will not decide for you.
Lesson Five: Screenshots Can Lie
My first plan for testing was simple: take a screenshot halfway through and look at it. In Chromium that works, and the filmstrip above was made that way. Playwright’s WebKit screenshots, though, leave out the transition layers entirely. They show the live page underneath at odd in-between opacities, so a “mid-flight” WebKit screenshot proves nothing.
What does work everywhere is asking the browser directly. After the new page is revealed, read the group’s computed style on every frame:
addEventListener("pagereveal", async ({ viewTransition }) => {
if (!viewTransition) return;
await viewTransition.ready;
const read = () => {
const group = getComputedStyle(
document.documentElement,
"::view-transition-group(site-nav-current)",
);
samples.push({ transform: group.transform, width: group.width });
requestAnimationFrame(read);
};
read();
});
That is how the frame-by-frame table above was recorded. The browser test checks the same thing a different way. It lists document.getAnimations() by pseudo-element and asserts exactly what should be running: one 230-millisecond glide between sections, and a single 160-millisecond fade-out on the way to Home.
expect((await revealed("/")).animations).toEqual([
"::view-transition-old(site-nav-current) site-nav-current-out 160ms",
]);
One more trap came up while probing the hidden-header case. A simulated click focuses the link, and focus brings the hidden header back, which quietly undoes the setup. Calling element.click() from a timer leaves the header hidden, the way it stays for a reader who clicks a link in the page. Lesson: for animation, trust measurements over pictures, and make sure the test is not changing the state it is measuring.
When It Stays Still
Some of the most important behavior is the bar not moving at all:
- Reduced motion: if your system asks for less motion, the bar never gets a name, so the new page simply shows it in place.
- Index to detail: going from Notes to a note keeps Notes current on both pages. Same name, same spot, so nothing visibly travels.
- Fixed chrome: the site’s design rules forbid sideways movement between peer pages, because it implies a back-and-forth relationship that does not exist. The underline gets an exception because it is a selection marker moving inside a header that never moves. The pages themselves still only fade.
That last point is the one I would keep if I lost the rest. The bar works because it is the only thing that travels. It connects two pages without asking you to notice the connection.