April 8, 2026SimplePage Transitions
View Transitions API
Old page scales down and slides up off screen. New page slides in from below. Uses the browser's native View Transitions API with document.startViewTransition(). No overlay components needed.
Preview
Home
Uses the native View Transitions API
Source
"use client";
import { useState, useCallback } from "react";
import styles from "./styles.module.css";
const PAGES = [
{ key: "home", label: "Home", bg: "#f5f5f5", color: "#1a1a1a" },
{ key: "about", label: "About", bg: "#0d0d0d", color: "#ffffff" },
{ key: "work", label: "Work", bg: "#1a1f2e", color: "#ffffff" },
];
export default function ViewTransitionsApi() {
const [pageIndex, setPageIndex] = useState(0);
const navigate = useCallback((nextIndex) => {
if (nextIndex === pageIndex) return;
if (!document.startViewTransition) {
setPageIndex(nextIndex);
return;
}
document.startViewTransition(() => {
setPageIndex(nextIndex);
});
}, [pageIndex]);
const page = PAGES[pageIndex];
return (
<div className={styles.demo}>
<div
className={styles.page}
style={{ background: page.bg, color: page.color }}
>
<h2 className={styles.pageTitle}>{page.label}</h2>
<p className={styles.hint}>Uses the native View Transitions API</p>
</div>
<div className={styles.nav}>
{PAGES.map((p, i) => (
<button
key={p.key}
className={`${styles.navBtn} ${i === pageIndex ? styles.active : ""}`}
onClick={() => navigate(i)}
>
{p.label}
</button>
))}
</div>
</div>
);
}