Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::view-transition-group() — view transition group

The ::view-transition-group() pseudo-element represents a named view transition group. It controls the group's geometry animation and the animation timing of its descendant old-state and new-state images.

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

Syntax

::view-transition-group(<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-group(card) selects the generated group for the name card assigned through view-transition-name. It does not select a DOM element. The group contains ::view-transition-image-pair(card), holding the old-state and new-state images; when both states exist, the browser animates the group's size and transform between them by default.

The argument * selects all groups; root is the document element's default transition name. Level 2 adds class selectors such as ::view-transition-group(.tile) and ::view-transition-group(card.tile), associated with view-transition-class, not the HTML class attribute. Spaces are forbidden between argument components. Empty () is invalid.

Apply the selector directly to the transition's root element, for example :root::view-transition-group(card) for a document transition; do not chain it as ::view-transition::view-transition-group(card). Setting animation-duration on the group also controls its descendants' animation timing by default. Do not confuse the pseudo-element with the view-transition-group property, which controls group nesting.

The example triggers an update through document.startViewTransition(), reduces motion according to prefers-reduced-motion, and provides an update without a transition when unsupported. Level 2 is a draft; verify the features used in the target browser independently of the Chromium 152 scope gate.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>View transition group</title>
<style>
  :root { view-transition-name: none; }
  #card {
    view-transition-name: card;
    width: 100px;
    height: 80px;
    background: royalblue;
    margin-top: 16px;
  }
  #card.moved { transform: translateX(160px); }
  ::view-transition-group(card) {
    animation-duration: 1s;
    animation-timing-function: linear;
  }
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(card) { animation-duration: 0s; }
  }
</style>
<button id="move" type="button">Move</button>
<p id="status" role="status">Ready</p>
<div id="card"></div>
<script>
  const button = document.querySelector('#move');
  const card = document.querySelector('#card');
  const status = document.querySelector('#status');
  button.addEventListener('click', async () => {
    button.disabled = true;
    const update = () => card.classList.toggle('moved');
    try {
      if (document.startViewTransition &&
          CSS.supports('selector(::view-transition-group(card))')) {
        const transition = document.startViewTransition(update);
        await transition.finished;
        status.textContent = 'Finished';
      } else {
        update();
        status.textContent = 'Updated without transition';
      }
    } finally {
      button.disabled = false;
    }
  });
</script>
</html>

Result

First click: the blue box ends 160 CSS pixels to the right. With an active supported transition and no reduced-motion preference, movement takes approximately 1 second and the status becomes "Finished". Without support, the box updates immediately and the status becomes "Updated without transition". The next click returns it.

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