Skip to content

View Transitions API Page Transition

Playlist grid and detail views that cross-fade with the native View Transitions API, morphing the cover art between views, with an instant fallback.

Also known as: view transitions api, page transition animation, master detail transition, shared element transition, cover morph transition

View Transitions API Page Transition live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A playlist library that switches between a grid view and a detail view with the native View Transitions API. The old view fades out, the new one fades in, and the cover art morphs from its card into the large detail cover. It is plain HTML, CSS and a small vanilla JavaScript file, useful as a starting point for master-detail screens, galleries or app-like navigation without a framework.

How it works

The root section.vtx-app contains a .vtx-stage with several .vtx-view elements: one grid view (data-vtx-view="grid") and one article.vtx-view--detail per playlist. Only one view is visible; the others carry the hidden attribute. Each .vtx-card button has a data-vtx-open value that matches the data-vtx-view of its detail view, and each detail view has a .vtx-back button with data-vtx-back.

The script listens for click on the root. Before switching, it gives the clicked card's .vtx-cover a unique view-transition-name and calls document.startViewTransition(). Inside the update callback it hides the old view, shows the new one and moves the same name to the large cover, so the browser animates one cover into the other. The stage gets its own name per instance and the class vtx-stage through view-transition-class, which lets the shared CSS style ::view-transition-old(*.vtx-stage) and ::view-transition-new(*.vtx-stage) with the vtx-fade-out and vtx-fade-in keyframes. Pressing Escape inside a detail view returns to the grid. In browsers without the API the views simply swap instantly.

Customization

  • --vtx-bg, --vtx-surface and --vtx-accent on .vtx-app: the background, card color and accent used for the eyebrow, track numbers and focus rings.
  • .vtx-cover--sun, .vtx-cover--sea, .vtx-cover--night and .vtx-cover--leaf: each sets --vtx-c1 and --vtx-c2, the two gradient stops of a cover. Add a modifier for a new playlist color.
  • animation-duration in ::view-transition-group(*.vtx-cover): how long the cover morph takes, 0.45s by default.
  • The vtx-fade-out and vtx-fade-in keyframes: change the translateY values or add a scale() for a different page feel.
  • grid-template-columns in .vtx-grid: two columns on phones and four from 720px.
  • Add a new playlist by copying a .vtx-card and an article.vtx-view--detail, then give both the same data-vtx-open / data-vtx-view value.

Use cases

  • Music and podcast apps: a playlist cover morphs from its grid card into the large detail view
  • Galleries: switch between grid and detail views with a cross-fade and no framework
  • App-like websites: master-detail screens feel smooth while falling back to an instant swap in older browsers
  • Media libraries: a back button and Escape key return to the grid and restore focus
  • Front-end prototypes: a starting point for learning how to use document.startViewTransition() in practice

Accessibility

Cards and the back button are real button elements with visible :focus-visible outlines. After a switch, focus moves to the detail heading (tabindex="-1"), and going back returns focus to the card that opened it. A visually hidden .vtx-status region with aria-live="polite" announces the current view. With prefers-reduced-motion: reduce the script skips the transition and the CSS shortens all view transition animations.

Usage notes

View Transitions with view-transition-class work in current Chromium browsers and Safari 18.2+; other browsers fall back to an instant swap. Several instances can share a page because the names include an index.

View Transitions API Page Transition at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Page Transitions
License
Free for personal and commercial use

Questions about this template

Can I use the View Transitions API Page Transition code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

View Transitions API Page Transition – Pure CSS page transitions component screenshot
View Transitions API Page Transition · Pure CSS Page Transitions