Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::view-transition-image-pair() — transition image-pair container

The ::view-transition-image-pair() pseudo-element groups corresponding old-state and new-state images during a view transition. It lets you clip those images together and control the isolation of their blending.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

::view-transition-image-pair(<pt-name-and-class-selector>)
<pt-name-and-class-selector> = <pt-name-selector> <pt-class-selector>? | <pt-class-selector>
<pt-name-selector> = '*' | <custom-ident>
<pt-class-selector> = ['.' <custom-ident>]+

::view-transition-image-pair() is a generated container inside its corresponding ::view-transition-group(). It contains ::view-transition-old(), ::view-transition-new(), or both, in that order. It is not an ordinary DOM element: it represents transition images, not the source element itself.

The argument card matches the name assigned through view-transition-name: card, while * matches all names. Level 2 also allows view-transition-class classes, such as ::view-transition-image-pair(.tile) or ::view-transition-image-pair(card.tile). Whitespace is forbidden between the name and classes and between class components. Empty () is not a valid selector.

The default transition styles set isolation: isolate on the pair only when both the old and new images are present. This prevents those images from blending with content outside the pair. Usually you style the group or individual images; this container is useful for shared clipping. In the example, rounding exists only during the transition because the rule does not change #card.

The Level 2 document is a draft, not a support guarantee. Check the example in the target browser; availability of document.startViewTransition does not establish support for every selector variant.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Image pair clipping</title>
<style>
  :root { view-transition-name: none; }
  #card {
    view-transition-name: card;
    width: 180px;
    padding: 32px;
    background: navy;
    color: white;
  }
  #card.changed { background: maroon; }
  ::view-transition-group(card) { animation-duration: 2s; }
  ::view-transition-image-pair(card) {
    border-radius: 32px;
    overflow: clip;
  }
</style>
<button id="change" type="button">Change</button>
<p id="card">Before</p>
<script>
  const button = document.querySelector('#change');
  const card = document.querySelector('#card');
  button.addEventListener('click', async () => {
    button.disabled = true;
    const update = () => {
      card.classList.add('changed');
      card.textContent = 'After';
    };
    if (!document.startViewTransition) {
      update();
      return;
    }
    const transition = document.startViewTransition(update);
    await transition.finished;
  });
</script>
</html>

Result

Before → After

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources