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

Crossfade

Also called cross-fade or cross dissolve

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

import { useState } from 'react';

const photos = [
  { src: '/photos/lake.jpg', alt: 'Morning fog over a mountain lake' },
  { src: '/photos/dunes.jpg', alt: 'Sand dunes at sunset' },
  { src: '/photos/forest.jpg', alt: 'Sunlight through a pine forest' }
];

export function PhotoViewer() {
  const [active, setActive] = useState(0);

  return (
    <div className='w-96'>
      {/* Every photo sits in the same grid cell, so the old and new one overlap while they fade. */}
      <div className='grid aspect-4/3 overflow-hidden rounded-2xl bg-muted'>
        {photos.map((photo, index) => (
          <img
            key={photo.src}
            src={photo.src}
            alt={photo.alt}
            aria-hidden={index !== active}
            className={`col-start-1 row-start-1 size-full object-cover transition-opacity duration-300 ease-in-out ${index === active ? 'opacity-100' : 'opacity-0'}`}
          />
        ))}
      </div>
      <div className='mt-3 flex gap-2'>
        {photos.map((photo, index) => (
          <button
            key={photo.src}
            type='button'
            aria-label={photo.alt}
            aria-pressed={index === active}
            onClick={() => setActive(index)}
            className='overflow-hidden rounded-lg opacity-60 transition-opacity aria-pressed:opacity-100 aria-pressed:ring-2 aria-pressed:ring-ring'
          >
            <img src={photo.src} alt='' className='size-14 object-cover' />
          </button>
        ))}
      </div>
    </div>
  );
}
When the selected photo changes, crossfade from the old image to the new one: stack both in the same spot and animate opacity over 300ms with ease-in-out, fading the new image in while the old one fades out, with no blank frame in between. Keep the image container at a fixed aspect ratio so nothing shifts during the fade.

Paste into Layerwise or any AI coding tool.

What is Crossfade?

A crossfade swaps one thing for another in place. Both versions sit on top of each other and their opacity changes at the same time: the old one goes from 1 to 0 while the new one goes from 0 to 1. There is never an empty moment, so the change feels calm and quick.

Use it when content changes but its position stays the same: a new photo in a gallery, an icon switching from play to pause, a tab panel, a label that updates. If the content also moves or resizes, pair the crossfade with a layout animation or use a morph.

A common mistake is fading the old content out completely before fading the new one in. That leaves a blank flash in the middle and makes the change feel slower. Stack both versions in the same spot, for example in a single CSS Grid cell or with absolute positioning, so they can overlap. Keep it short: 150 to 300ms for small UI and up to 500ms for large images.

Often confused with

Fade in
A fade-in brings one element onto the screen. A crossfade replaces one element with another by fading both at once.

Related terms

All terms

Fade in

An entrance animation where an element goes from fully transparent to fully visible, so it appears gently instead of popping in.

Morph

A transition where one shape smoothly changes its size, corners, and contents into another, like a small pill growing into a full card.

View Transitions API

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.

Enter and exit animations

The pair of animations an element plays as it is added to the page and as it is removed, so changes to a list or layout are easy to follow.

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

Crossfade

Dunes

2:40 PM

Aurora

11:52 PM

Fade out, then in

Dunes

2:40 PM

Aurora

11:52 PM