--- title: 'Transitions' description: Apply transitions between pages and layouts with Vue or native browser View Transitions. navigation.icon: i-ph-exclude-square-duotone --- ::callout Nuxt leverages Vue's [``](https://vuejs.org/guide/built-ins/transition.html#the-transition-component) component to apply transitions between pages and layouts. :: ## Page transitions You can enable page transitions to apply an automatic transition for all your [pages](/docs/guide/directory-structure/pages). ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ app: { pageTransition: { name: 'page', mode: 'out-in' } }, }) ``` ::callout If you are changing layouts as well as page, the page transition you set here will not run. Instead, you should set a [layout transition](/docs/getting-started/transitions#layout-transitions). :: To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/guide/directory-structure/app): ::code-group ```vue [app.vue] ``` ```vue [pages/index.vue] ``` ```vue [pages/about.vue] ``` :: This produces the following result when navigating between pages: To set a different transition for a page, set the `pageTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page: ::code-group ```vue twoslash [pages/about.vue] ``` ```vue [app.vue] ``` :: Moving to the about page will add the 3d rotation effect: ## Layout transitions You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/guide/directory-structure/layouts). ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ app: { layoutTransition: { name: 'layout', mode: 'out-in' } }, }) ``` To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/guide/directory-structure/app): ::code-group ```vue [app.vue] ``` ```vue [layouts/default.vue] ``` ```vue [layouts/orange.vue] ``` ```vue [pages/index.vue] ``` ```vue [pages/about.vue] ``` :: This produces the following result when navigating between pages: Similar to `pageTransition`, you can apply a custom `layoutTransition` to the page component using `definePageMeta`: ```vue twoslash [pages/about.vue] ``` ## Global settings You can customize these default transition names globally using `nuxt.config`. Both `pageTransition` and `layoutTransition` keys accept [`TransitionProps`](https://vuejs.org/api/built-in-components.html#transition) as JSON serializable values where you can pass the `name`, `mode` and other valid transition-props of the custom CSS transition. ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ app: { pageTransition: { name: 'fade', mode: 'out-in' // default }, layoutTransition: { name: 'slide', mode: 'out-in' // default } } }) ``` ::callout If you change the `name` property, you also have to rename the CSS classes accordingly. :: To override the global transition property, use the `definePageMeta` to define page or layout transitions for a single Nuxt page and override any page or layout transitions that are defined globally in `nuxt.config` file. ```vue twoslash [pages/some-page.vue] ``` ## Disable Transitions `pageTransition` and `layoutTransition` can be disabled for a specific route: ```vue twoslash [pages/some-page.vue] ``` Or globally in the `nuxt.config`: ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ app: { pageTransition: false, layoutTransition: false } }) ``` ## JavaScript Hooks For advanced use-cases, you can use JavaScript hooks to create highly dynamic and custom transitions for your Nuxt pages. This way presents perfect use-cases for JavaScript animation libraries such as [GSAP](https://gsap.com). ```vue twoslash [pages/some-page.vue] ``` ::callout Learn more about additional [JavaScript hooks](https://vuejs.org/guide/built-ins/transition.html#javascript-hooks) available in the `Transition` component. :: ## Dynamic Transitions To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/guide/directory-structure/middleware) to assign a different transition name to `to.meta.pageTransition`. ::code-group ```vue twoslash [pages/[id\\].vue] ``` ```vue [layouts/default.vue] ``` :: The page now applies the `slide-left` transition when going to the next id and `slide-right` for the previous: ## Transition with NuxtPage When `` is used in `app.vue`, transition-props can be passed directly as a component props to activate global transition. ```vue [app.vue] ``` ::callout Remember, this page transition cannot be overridden with `definePageMeta` on individual pages. :: ## View Transitions API (experimental) Nuxt ships with an experimental implementation of the [**View Transitions API**](https://developer.chrome.com/docs/web-platform/view-transitions) (see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)). This is an exciting new way to implement native browser transitions which (among other things) have the ability to transition between unrelated elements on different pages. You can check a demo on https://nuxt-view-transitions.surge.sh and the [source on StackBlitz](https://stackblitz.com/edit/nuxt-view-transitions). The Nuxt integration is under active development, but can be enabled with the `experimental.viewTransition` option in your configuration file: ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ experimental: { viewTransition: true } }) ``` The possible values are: `false`, `true`, or `'always'`. If set to true, Nuxt will not apply transitions if the user's browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition and it is up to you to respect the user's preference. By default, view transitions are enabled for all [pages](/docs/guide/directory-structure/pages), but you can set a different global default. ```ts twoslash [nuxt.config.ts] export default defineNuxtConfig({ app: { // Disable view transitions globally, and opt-in on a per page basis viewTransition: false }, }) ``` It is possible to override the default `viewTransition` value for a page by setting the `viewTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page: ```vue twoslash [pages/about.vue] ``` ::alert{type="warning"} Overriding view transitions on a per-page basis will only have an effect if you have enabled the `experimental.viewTransition` option. :: If you are also using Vue transitions like `pageTransition` and `layoutTransition` (see above) to achieve the same result as the new View Transitions API, then you may wish to _disable_ Vue transitions if the user's browser supports the newer, native web API. You can do this by creating `~/middleware/disable-vue-transitions.global.ts` with the following contents: ```ts export default defineNuxtRouteMiddleware(to => { if (import.meta.server || !document.startViewTransition) { return } // Disable built-in Vue transitions to.meta.pageTransition = false to.meta.layoutTransition = false }) ``` ### Known issues - View transitions may not work as expected with nested pages/layouts/async components owing to this upstream Vue bug: . If you make use of this pattern, you may need to delay adopting this experimental feature or implement it yourself. Feedback is very welcome. - If you perform data fetching within your page setup functions, that you may wish to reconsider using this feature for the moment. (By design, View Transitions completely freeze DOM updates whilst they are taking place.) We're looking at restrict the View Transition to the final moments before `` resolves, but in the interim you may want to consider carefully whether to adopt this feature if this describes you.