Skip to content
العربية
Motion

data-page-transition

Page changes with the browser's View Transitions. Opt in on <html>: fade (a short cross-fade) or slash (the new page wipes in behind an edge at the slash angle, in the reading direction). Navigate with React Router's viewTransition: make the link of PercentProvider pass it. Without the attribute nothing changes; browsers without View Transitions navigate as usual. No animation with reduced motion.

@import "@percentsa/motion/styles.css";

Examples

app/root.tsx
// app/root.tsx: opt in on <html>, "fade" or "slash".
<html lang={lang} dir={dir} data-page-transition="slash">

// The app's link passes viewTransition to React Router,
// except for links to a place on the same page.
const RouterLink = ({ href = "#", ...p }: ComponentProps<"a">) => (
  <Link to={href} viewTransition={!href.startsWith("#")} {...p} />
);
<PercentProvider lang={lang} link={RouterLink}>…</PercentProvider>

// Navigating from code:
navigate("/en/work", { viewTransition: true });

Try it: open the page p-slash-hover.

Code
export function PageTransitionExample() {
  const t = useT();
  const lang = useLang();
  const code = `// app/root.tsx: opt in on <html>, "fade" or "slash".
<html lang={lang} dir={dir} data-page-transition="slash">

// The app's link passes viewTransition to React Router,
// except for links to a place on the same page.
const RouterLink = ({ href = "#", ...p }: ComponentProps<"a">) => (
  <Link to={href} viewTransition={!href.startsWith("#")} {...p} />
);
<PercentProvider lang={lang} link={RouterLink}>…</PercentProvider>

// Navigating from code:
navigate("/${lang}/work", { viewTransition: true });`;
  return (
    <Stack gap={6} className="w-full max-w-2xl">
      <CodeBlock code={code} filename="app/root.tsx" />
      <Text tone="muted">
        {t("Try it: open the page ", "جرّبها: افتح صفحة ")}
        <Link href={`/${lang}/components/slash-hover`}>p-slash-hover</Link>
        .
      </Text>
    </Stack>
  );
}