LayerwiseLayerwise
  • Features
  • Pricing
  • Templates
  • Docs
DownloadDownload
FeaturesPricingTemplatesDocsAI Website BuilderVibe CodingPersonal Software
DownloadDownload
  1. Glossary
  2. /
  3. State transitions

View Transitions API

Also called CSS view transitions or startViewTransition

A browser feature that animates between two states of a page by snapshotting the old view, applying your update, and animating to the new one.

import { useState } from 'react';
import { flushSync } from 'react-dom';

const products = [
  { id: 'chair', name: 'Lounge chair', price: '$420' },
  { id: 'lamp', name: 'Arc floor lamp', price: '$180' },
  { id: 'table', name: 'Oak side table', price: '$240' }
];
type Product = (typeof products)[number];

function viewTransition(update: () => void) {
  const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
  if (!document.startViewTransition || reduceMotion) return update();
  // flushSync commits the new view inside the callback, before the browser snapshots it.
  document.startViewTransition(() => flushSync(update));
}

// Matching names pair a thumbnail with the hero image. Each name is unique on the page.
const image = (product: Product) => ({
  src: `/products/${product.id}.jpg`,
  style: { viewTransitionName: `product-${product.id}` },
  className: 'aspect-square w-full rounded-xl object-cover'
});

export function ProductBrowser() {
  const [selected, setSelected] = useState<Product | null>(null);
  const show = (next: Product | null) =>
    viewTransition(() => setSelected(next));

  if (selected) {
    return (
      <article className='w-80'>
        <img {...image(selected)} alt={selected.name} />
        <h2 className='mt-4 text-xl font-semibold'>{selected.name}</h2>
        <p className='text-muted-foreground'>{selected.price}</p>
        <button
          type='button'
          onClick={() => show(null)}
          className='mt-4 rounded-full border px-4 py-2 text-sm font-medium'
        >
          All products
        </button>
      </article>
    );
  }

  return (
    <ul className='grid w-80 grid-cols-3 gap-3 text-sm'>
      {products.map((product) => (
        <li key={product.id}>
          <button type='button' onClick={() => show(product)}>
            <img {...image(product)} alt='' />
            {product.name}
          </button>
        </li>
      ))}
    </ul>
  );
}
Use the View Transitions API to animate switching between the product list and the product detail view: wrap the state update in document.startViewTransition(), give the clicked product image view-transition-name: product-image on both views so it grows from the thumbnail into the hero, and crossfade the rest over 300ms. Fall back to an instant update when document.startViewTransition is missing, and disable the animations under prefers-reduced-motion.

Paste into Layerwise or any AI coding tool.

View Transitions API explained

The View Transitions API lets the browser do the hard part of a transition. You call document.startViewTransition() with a function that updates the page. The browser captures a snapshot of the current page, runs your update, then animates from the old snapshot to the new, live view. By default, the whole page crossfades.

Give an element a view-transition-name and the browser animates it separately: it moves and resizes that element from its old position to its new one while the rest of the page crossfades. That is how a thumbnail can grow into a hero image without an animation library. Each name must be unique on the page at the moment of the snapshot.

Customize the motion with CSS pseudo-elements such as ::view-transition-old(root) and ::view-transition-new(root), using ordinary animation properties. For multi-page sites, adding @view-transition { navigation: auto; } to both pages animates same-origin navigations in browsers that support it. The old view is a still image during the animation, so keep it short.

Same-document transitions work in current versions of Chrome, Edge, Safari, and Firefox; cross-document support is less complete. Check that document.startViewTransition exists and call your update directly when it does not, and turn the animations off for people who prefer reduced motion.

Often confused with

Page transition
A page transition is any animation between pages. The View Transitions API is a built-in browser way to create one, with or without a JavaScript animation library.

Related terms

All terms

Shared element transition

A transition where an element from one view, like a thumbnail, travels and grows into its place in the next view, linking the two screens.

Crossfade

A transition where the old content fades out while the new content fades in at the same spot, so the two briefly overlap.

Reduced motion

An operating system setting that asks apps to minimize movement, which websites detect with the prefers-reduced-motion media query.

Page transition

An animation that plays when you move from one page or screen to another, such as the old page fading out as the new one fades in.

Build it with Layerwise

Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.

DownloadDownloadRead the docs
LayerwiseLayerwise

Build full-stack web apps in minutes with AI.

Product

  • Features
  • Pricing
  • Download
  • Templates

Solutions

  • AI Website Builder
  • Vibe Coding
  • Personal Software

Resources

  • Documentation
  • Changelog
  • Blog
  • Vibe Coding Glossary
  • llms.txt
  • llms-full.txt

Company

  • About
  • Contact

Legal

  • Privacy
  • Analytics Privacy
  • Terms
  • Security
  • Abuse

© 2026 Layerwise. All rights reserved.

Entrances & exits

  • Fade in
  • Slide in
  • Scale in
  • Pop in
  • Blur in
  • Reveal animation
  • Enter and exit animations

Timing & sequencing

  • Duration
  • Delay
  • Keyframes
  • Tweening
  • Stagger
  • Orchestration
  • Fill mode
  • Stepped animation
  • Looping animation
  • Yoyo animation

Easing

  • Easing
  • Linear easing
  • Ease-in
  • Ease-out
  • Ease-in-out
  • Cubic-bezier
  • Asymmetric easing
  • Overshoot easing

Springs & physics

  • Spring animation
  • Stiffness
  • Damping
  • Mass
  • Bounce
  • Velocity
  • Momentum
  • Interruptible animation
  • Rubber-banding

Transforms

  • Translate
  • Scale
  • Rotate
  • Skew
  • 3D flip
  • Perspective
  • Transform origin
  • Origin-aware animation

State transitions

  • Crossfade
  • Morph
  • Shared element transition
  • Layout animation
  • Height auto animation
  • Direction-aware transition
  • Continuity transition
  • Page transition
  • View Transitions API

Scroll effects

  • Scroll reveal
  • Scroll-driven animation
  • Parallax scrolling
  • Scrollytelling
  • Scroll pinning
  • Horizontal scroll section
  • Scroll progress bar
  • Scroll snap
  • Smooth scrolling

Interaction feedback

  • Hover effect
  • Press feedback
  • Ripple effect
  • Shake animation
  • Hold to confirm
  • Drag gesture
  • Drag to reorder
  • Swipe to dismiss
  • Pull to refresh
  • Magnetic button
  • Custom cursor
  • 3D tilt card
  • Spotlight card

Text effects

  • Typewriter effect
  • Text scramble
  • Split text animation
  • Text morph
  • Rotating words
  • Gradient text
  • Shimmer text
  • Number ticker
  • Tabular numbers
  • Underline animation

Loops & ambient motion

  • Marquee
  • Pulse animation
  • Float animation
  • Orbit animation
  • Idle animation
  • Particle background
  • Border beam
  • Confetti
  • Animated gradient

Visual effects

  • Blur
  • Clip-path
  • Mask
  • Before/after slider
  • SVG line drawing
  • Lottie animation

Motion principles

  • Purposeful animation
  • Anticipation
  • Follow-through
  • Squash and stretch
  • Perceived performance
  • Frequency of use
  • Spatial consistency
  • Reduced motion

Animation performance

  • Frame rate (FPS)
  • Jank
  • GPU acceleration
  • will-change
  • Layout thrashing

Layout

  • Hero section
  • Above the fold
  • Sticky header
  • Sidebar
  • Bento grid
  • Card
  • Flexbox
  • CSS Grid
  • Padding vs margin
  • Responsive design
  • Container
  • Masonry layout
  • Split screen
  • Z-index
  • Overflow

Components

  • Button variants
  • Modal
  • Drawer
  • Popover
  • Tooltip
  • Dropdown menu
  • Context menu
  • Toast notification
  • Tabs
  • Segmented control
  • Accordion
  • Carousel
  • Command palette
  • Combobox
  • Toggle switch
  • Checkbox
  • Radio button
  • Date picker
  • Breadcrumb
  • Pagination
  • Infinite scroll
  • Badge
  • Avatar stack
  • Empty state
  • Skeleton screen
  • Spinner
  • Progress bar
  • Data table
  • Stepper
  • Floating label
  • Inline validation
  • Alert banner
  • Tag input

States & patterns

  • Interaction states
  • Focus ring
  • Loading state
  • Optimistic UI
  • Debounce
  • Lazy loading
  • Dark mode
  • Micro-interaction
  • Affordance
  • Undo
  • Drag and drop
  • Keyboard shortcut

Visual styles

  • Glassmorphism
  • Liquid glass
  • Neumorphism
  • Claymorphism
  • Neo-brutalism
  • Skeuomorphism
  • Flat design
  • Mesh gradient
  • Aurora background
  • Grain texture
  • Glow effect
  • Drop shadow
  • Border radius
  • Grid background
  • Typographic hierarchy
  • Accent color
  • Color contrast

Vibe coding & AI

  • Vibe coding
  • Prompt
  • Context window
  • Token
  • AI agent
  • Tool call
  • Hallucination
  • Diff
  • Live preview
  • Checkpoint
  • Git commit
  • Deploy
  • Frontend and backend
  • API
  • Database
  • Rules file
  • MCP
  • Plan mode
  • Visual edit

Shop

A latte with leaf art in a white cupCoffee cup$24
Monstera$38
A maroon canvas sneaker on a yellow backgroundCanvas sneaker$68
Monstera leaves against a white wall
startViewTransition()
  1. 1Snapshot the old view
  2. 2Run your update
  3. 3Animate old to new