View Transitions
Astro supports opt-in, per-page, view transitions with just a few lines of code. View transitions update your page content without the browser’s normal, full-page navigation refresh and provide seamless animations between pages.
Astro provides a <ViewTransitions />
routing component that can be added to a single page’s <head>
to control page transitions as you navigate away to another page. It provides a lightweight client-side router that intercepts navigation and allows you to customize the transition between pages.
Add this component to a reusable .astro
component, such as a common head or layout, for animated page transitions across your entire site (SPA mode).
Astro’s view transitions support is powered by the new View Transitions browser API and also includes:
- A few built-in animation options, such as
fade
,slide
, andnone
. - Support for both forwards and backwards navigation animations.
- The ability to fully customize all aspects of transition animation, and build your own animations.
- The option to prevent client-side navigation for non-page links.
- Control over fallback behavior for browsers that do not yet support the View Transition APIs.
- Automatic support for
prefers-reduced-motion
.
By default, every page will use regular, full-page, browser navigation. You must opt in to view transitions and can use them either on a per-page basis or site-wide.
Adding View Transitions to a Page
Section titled Adding View Transitions to a PageOpt in to using view transitions on individual pages by importing and adding the <ViewTransitions />
routing component to <head>
on every desired page.