CSS Portal

::view-transition-image-pair() CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::view-transition-image-pair() pseudo-element represents the paired visual snapshot used during a View Transition animation. It acts as a temporary container that visually groups the old and new renderings of an element while a transition is occurring. This pairing allows the browser to animate between two visual states smoothly, enabling effects such as crossfades, morphs, slides, or custom transforms. Unlike regular pseudo-elements, this one exists only during an active view transition and is automatically created and removed by the browser.

During a transition, the browser captures two visual representations of an element: one from before the DOM update and one from after. These are internally represented by ::view-transition-old() and ::view-transition-new(). The ::view-transition-image-pair() pseudo-element acts as their shared wrapper, allowing developers to apply transformations, clipping, opacity changes, or layout adjustments that affect both states together. This is especially useful when you want to control how the two snapshots relate spatially during the animation rather than styling them independently.

The pseudo-element is commonly styled using properties such as transform, opacity, animation, or clip-path. Because it represents a visual composite rather than a real DOM node, layout-affecting properties like width or display usually have no effect. Instead, it is best used for visual continuity - such as scaling content during navigation or creating zoom-style transitions between views.

A common use case is animating between pages or UI states triggered by JavaScript or navigation. The example below demonstrates how ::view-transition-image-pair() can be used to apply a smooth zoom effect during a transition:

::view-transition-image-pair(root) {
  animation: zoom-fade 400ms ease-in-out;
}

@keyframes zoom-fade {
  from {
    transform: scale(0.95);
    opacity: 0.6;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

In this example, the transition applies to the root view, smoothly scaling and fading between the old and new visual states. This works especially well when combined with navigation updates triggered via JavaScript or interactions inside elements such as main or section containers.

Syntax

::view-transition-image-pair([ <pt-name-selector> <pt-class-selector>? ] | <pt-class-selector>) {
  /* ... */
}

Values

  • <pt-name-selector>This is the name you assigned to the element via the view-transition-name property.

Example

<div class="gallery">
<img id="main-image" src="https://picsum.photos/id/237/400/300" alt="Puppy">
</div>

<button onclick="changeImage()">Switch Image</button>
<script>
function changeImage() {
const img = document.getElementById('main-image');

// Check for browser support
if (!document.startViewTransition) {
img.src = "https://picsum.photos/id/1025/400/300";
return;
}

// Start the transition
document.startViewTransition(() => {
// Logic to toggle the image source
if (img.src.includes('237')) {
img.src = "https://picsum.photos/id/1025/400/300";
} else {
img.src = "https://picsum.photos/id/237/400/300";
}
});
}
</script>
/* 1. Assign a unique name to the element being transitioned */
#main-image {
view-transition-name: hero-image;
}

/* 2. Target the wrapper of the old and new snapshots */
::view-transition-image-pair(hero-image) {
border: 4px solid #6200ee;
border-radius: 20px;
overflow: hidden;
/* You can add custom animations to the pair itself */
animation: scale-up 0.5s ease-in-out;
}

/* 3. Custom animation for the container */
@keyframes scale-up {
from { transform: scale(0.8); }
to { transform: scale(1); }
}

/* Optional: Styling the old and new states specifically */
::view-transition-old(hero-image) {
filter: grayscale(1);
}

::view-transition-new(hero-image) {
filter: sepia(1);
}

Browser Support

The following information will show you the current browser support for the CSS ::view-transition-image-pair() pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!