Skip to content

View Transitions

WARNING You're browsing the documentation for an old version of Inertia. Consider upgrading your project to Inertia 3.x.

The Basics

View Transitions

v2.2.13+

Inertia supports the View Transitions API, allowing you to animate page transitions.

The View Transitions API is a relatively new browser feature. Inertia gracefully falls back to standard page transitions in browsers that don't support the API.

Enabling Transitions

You may enable view transitions for a visit by setting the viewTransition option to true. By default, this will apply a cross-fade transition between pages.

1import { router } from '@inertiajs/vue3'
2 
3router.visit('/another-page', { viewTransition: true })
1import { router } from '@inertiajs/vue3'
2 
3router.visit('/another-page', { viewTransition: true })
1import { router } from '@inertiajs/react'
2 
3router.visit('/another-page', { viewTransition: true })
1import { router } from '@inertiajs/react'
2 
3router.visit('/another-page', { viewTransition: true })
1import { router } from '@inertiajs/svelte'
2 
3router.visit('/another-page', { viewTransition: true })
1import { router } from '@inertiajs/svelte'
2 
3router.visit('/another-page', { viewTransition: true })

Transition Callbacks

You may also pass a callback to the viewTransition option, which will receive the standard ViewTransition instance provided by the browser. This allows you to hook into the various promises provided by the API.

1import { router } from '@inertiajs/vue3'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})
1import { router } from '@inertiajs/vue3'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})
1import { router } from '@inertiajs/react'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})
1import { router } from '@inertiajs/react'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})
1import { router } from '@inertiajs/svelte'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})
1import { router } from '@inertiajs/svelte'
2 
3router.visit('/another-page', {
4 viewTransition: (transition) => {
5 transition.ready.then(() => console.log('Transition ready'))
6 transition.updateCallbackDone.then(() => console.log('DOM updated'))
7 transition.finished.then(() => console.log('Transition finished'))
8 },
9})

The viewTransition option is also available on the Link component.

1import { Link } from '@inertiajs/vue3'
2 
3<Link href="/another-page" view-transition>Navigate</Link>
1import { Link } from '@inertiajs/vue3'
2 
3<Link href="/another-page" view-transition>Navigate</Link>
1import { Link } from '@inertiajs/react'
2 
3<Link href="/another-page" viewTransition>Navigate</Link>
1import { Link } from '@inertiajs/react'
2 
3<Link href="/another-page" viewTransition>Navigate</Link>
1import { Link } from '@inertiajs/svelte'
2 
3<Link href="/another-page" viewTransition>Navigate</Link>
1import { Link } from '@inertiajs/svelte'
2 
3<Link href="/another-page" viewTransition>Navigate</Link>

You may also pass a callback to access the ViewTransition instance.

1import { Link } from '@inertiajs/vue3'
2 
3<Link
4 href="/another-page"
5 :view-transition="(transition) => transition.finished.then(() => console.log('Done'))"
6>
7 Navigate
8</Link>
1import { Link } from '@inertiajs/vue3'
2 
3<Link
4 href="/another-page"
5 :view-transition="(transition) => transition.finished.then(() => console.log('Done'))"
6>
7 Navigate
8</Link>
1import { Link } from '@inertiajs/react'
2 
3<Link
4 href="/another-page"
5 viewTransition={(transition) => transition.finished.then(() => console.log('Done'))}
6>
7 Navigate
8</Link>
1import { Link } from '@inertiajs/react'
2 
3<Link
4 href="/another-page"
5 viewTransition={(transition) => transition.finished.then(() => console.log('Done'))}
6>
7 Navigate
8</Link>
1import { Link } from '@inertiajs/svelte'
2 
3<Link
4 href="/another-page"
5 viewTransition={(transition) => transition.finished.then(() => console.log('Done'))}
6>
7 Navigate
8</Link>
1import { Link } from '@inertiajs/svelte'
2 
3<Link
4 href="/another-page"
5 viewTransition={(transition) => transition.finished.then(() => console.log('Done'))}
6>
7 Navigate
8</Link>

Global Configuration

You may enable view transitions globally for all visits by configuring the visitOptions callback when initializing your Inertia app.

1import { createInertiaApp } from '@inertiajs/vue3'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})
1import { createInertiaApp } from '@inertiajs/vue3'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})
1import { createInertiaApp } from '@inertiajs/react'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})
1import { createInertiaApp } from '@inertiajs/react'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})
1import { createInertiaApp } from '@inertiajs/svelte'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})
1import { createInertiaApp } from '@inertiajs/svelte'
2 
3createInertiaApp({
4 // ...
5 defaults: {
6 visitOptions: (href, options) => {
7 return { viewTransition: true }
8 },
9 },
10})

Customizing Transitions

You may customize the transition animations using CSS. The View Transitions API uses several pseudo-elements that you can target with CSS to create custom animations. The following examples are taken from the Chrome documentation .

1@keyframes fade-in {
2 from { opacity: 0; }
3}
4@keyframes fade-out {
5 to { opacity: 0; }
6}
7@keyframes slide-from-right {
8 from { transform: translateX(30px); }
9}
10@keyframes slide-to-left {
11 to { transform: translateX(-30px); }
12}
13::view-transition-old(root) {
14 animation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out,
15 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
16}
17::view-transition-new(root) {
18 animation: 210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in,
19 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right;
20}
1@keyframes fade-in {
2 from { opacity: 0; }
3}
4@keyframes fade-out {
5 to { opacity: 0; }
6}
7@keyframes slide-from-right {
8 from { transform: translateX(30px); }
9}
10@keyframes slide-to-left {
11 to { transform: translateX(-30px); }
12}
13::view-transition-old(root) {
14 animation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out,
15 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
16}
17::view-transition-new(root) {
18 animation: 210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in,
19 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right;
20}

You may also animate individual elements between pages by assigning them a unique view-transition-name. For example, you may animate an avatar from a large size on a profile page to a small size on a dashboard.

1<!-- Profile.vue -->
2<template>
3 <img src="/avatar.jpg" alt="User" class="avatar-large" />
4</template>
5 
6<style>
7.avatar-large {
8 view-transition-name: user-avatar;
9 width: auto;
10 height: 200px;
11}
12</style>
13 
14<!-- Dashboard.vue -->
15<template>
16 <img src="/avatar.jpg" alt="User" class="avatar-small" />
17</template>
18 
19<style>
20.avatar-small {
21 view-transition-name: user-avatar;
22 width: auto;
23 height: 40px;
24}
25</style>
1<!-- Profile.vue -->
2<template>
3 <img src="/avatar.jpg" alt="User" class="avatar-large" />
4</template>
5 
6<style>
7.avatar-large {
8 view-transition-name: user-avatar;
9 width: auto;
10 height: 200px;
11}
12</style>
13 
14<!-- Dashboard.vue -->
15<template>
16 <img src="/avatar.jpg" alt="User" class="avatar-small" />
17</template>
18 
19<style>
20.avatar-small {
21 view-transition-name: user-avatar;
22 width: auto;
23 height: 40px;
24}
25</style>
1// Profile.jsx
2export default function Profile() {
3 return <img src="/avatar.jpg" alt="User" className="avatar-large" />
4}
5 
6// CSS
7.avatar-large {
8 view-transition-name: user-avatar;
9 width: auto;
10 height: 200px;
11}
12 
13// Dashboard.jsx
14export default function Dashboard() {
15 return <img src="/avatar.jpg" alt="User" className="avatar-small" />
16}
17 
18// CSS
19.avatar-small {
20 view-transition-name: user-avatar;
21 width: auto;
22 height: 40px;
23}
1// Profile.jsx
2export default function Profile() {
3 return <img src="/avatar.jpg" alt="User" className="avatar-large" />
4}
5 
6// CSS
7.avatar-large {
8 view-transition-name: user-avatar;
9 width: auto;
10 height: 200px;
11}
12 
13// Dashboard.jsx
14export default function Dashboard() {
15 return <img src="/avatar.jpg" alt="User" className="avatar-small" />
16}
17 
18// CSS
19.avatar-small {
20 view-transition-name: user-avatar;
21 width: auto;
22 height: 40px;
23}
1<!-- Profile.svelte -->
2<img src="/avatar.jpg" alt="User" class="avatar-large" />
3 
4<style>
5.avatar-large {
6 view-transition-name: user-avatar;
7 width: auto;
8 height: 200px;
9}
10</style>
11 
12<!-- Dashboard.svelte -->
13<img src="/avatar.jpg" alt="User" class="avatar-small" />
14 
15<style>
16.avatar-small {
17 view-transition-name: user-avatar;
18 width: auto;
19 height: 40px;
20}
21</style>
1<!-- Profile.svelte -->
2<img src="/avatar.jpg" alt="User" class="avatar-large" />
3 
4<style>
5.avatar-large {
6 view-transition-name: user-avatar;
7 width: auto;
8 height: 200px;
9}
10</style>
11 
12<!-- Dashboard.svelte -->
13<img src="/avatar.jpg" alt="User" class="avatar-small" />
14 
15<style>
16.avatar-small {
17 view-transition-name: user-avatar;
18 width: auto;
19 height: 40px;
20}
21</style>

You may customize view transitions to your liking using any CSS animations you wish. For more information, please consult the View Transitions API documentation .