Page slide transition
Slide between pages with a horizontal push animation — use the View Transitions API or pure CSS.
Quick implementation
/* View Transitions API: slide animation */
@view-transition {
navigation: auto;
}
::view-transition-old(root) {
animation: slide-out 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
::view-transition-new(root) {
animation: slide-in 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slide-out {
to { transform: translateX(-100%); opacity: 0; }
}
@keyframes slide-in {
from { transform: translateX(100%); opacity: 0; }
}
/* SPA fallback with pure CSS */
.page-container {
position: relative;
overflow: hidden;
}
.page {
position: absolute;
inset: 0;
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@media (prefers-reduced-motion: reduce) {
::view-transition-old(root),
::view-transition-new(root) {
animation-duration: 0.01s;
}
.page { transition-duration: 0.01s; }
}
Prompt this to your LLM
Includes role, constraints, two framework variants, and edge cases to handle.
You are a senior frontend engineer building page navigation transitions.
Goal: A horizontal slide animation between pages — the old page pushes left while the new page enters from the right.
Technical constraints:
- Use the View Transitions API (@view-transition { navigation: auto }) for MPA transitions.
- Override ::view-transition-old(root) and ::view-transition-new(root) with @keyframes slide-out / slide-in.
- Use cubic-bezier(0.4, 0, 0.2, 1) for a material-style ease.
- Use oklch() for all color values — no hex or rgba().
- Duration 0.3–0.5s for the slide.
Framework variant (pick one):
A) MPA — CSS only with @view-transition and ::view-transition pseudo-elements.
B) React SPA — use document.startViewTransition() in a route change handler, CSS handles the animation.
Edge cases to handle:
- Respect prefers-reduced-motion: reduce duration to near-instant or disable the transition.
- Provide a pure-CSS fallback for SPAs without View Transitions API support.
- Ensure the back navigation reverses the slide direction (right to left).
Return CSS + minimal JS for the SPA variant.
Why this matters in 2026
The View Transitions API brings app-like page transitions to multi-page websites without JavaScript animation libraries. A simple @view-transition { navigation: auto } rule enables cross-document transitions, and custom @keyframes on the ::view-transition-old and ::view-transition-new pseudo-elements let you control the animation. This is the native replacement for libraries like Barba.js and Swup.
The logic
When a navigation occurs, the browser snapshots the old page as ::view-transition-old(root) and renders the new page underneath as ::view-transition-new(root). The default animation is a cross-fade. By assigning @keyframes slide-out (translateX to -100%) to the old snapshot and @keyframes slide-in (translateX from 100%) to the new one, you get a horizontal push effect. Both pseudo-elements are composited layers, so the animation runs on the GPU.
Accessibility & performance
View Transitions are GPU-composited and non-blocking — the new page loads underneath while the animation plays. Always wrap custom animations in a prefers-reduced-motion check. For users with motion sensitivity, either skip the animation entirely or reduce it to a fast cross-fade. The API degrades gracefully: browsers without support simply navigate normally with no animation.