Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

view-transition-group — nesting transition groups

The view-transition-group property controls the hierarchy of named groups during a view transition, independently of DOM layout.

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

Syntax

view-transition-group: normal | contain | nearest | <custom-ident>;

view-transition-group controls nesting of ::view-transition-group(); it does not name a transition. It requires view-transition-name other than none.

The initial value normal uses the containing group established by the closest participating flat-tree ancestor with view-transition-group: contain. It is contain that establishes a grouping boundary for descendants. nearest selects the closest participating ancestor regardless of that ancestor’s value for this property.

<custom-ident> targets an ancestor by view-transition-name. Without a match, the draft algorithm uses the containing group; the value description suggests the direct root instead—the draft is inconsistent. Nesting uses ::view-transition-group-children().

The property is not inherited; animation is discrete. Do not confuse it with the ::view-transition-group() pseudo-element. This is a draft feature: verify behavior in the target browser.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Nested transition groups</title>
<style>
  #panel {
    view-transition-name: panel;
    view-transition-group: contain;
    width: 240px;
    padding: 16px;
    background: #ddd;
  }
  #tile {
    view-transition-name: tile;
    width: 48px;
    height: 48px;
    background: #165dcc;
  }
  #panel.moved #tile { transform: translateX(160px); }
  ::view-transition-group(*) { animation-duration: 1s; }
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) { animation-duration: 0s; }
  }
</style>
<button id="toggle" type="button">Toggle</button>
<div id="panel"><div id="tile"></div></div>
<p id="status" role="status">Ready</p>
<script>
  const panel = document.querySelector('#panel');
  const button = document.querySelector('#toggle');
  const status = document.querySelector('#status');
  button.addEventListener('click', async () => {
    button.disabled = true;
    const update = () => panel.classList.toggle('moved');
    try {
      if (document.startViewTransition &&
          CSS.supports('view-transition-group', 'contain')) {
        const transition = document.startViewTransition(update);
        await transition.finished;
        status.textContent = 'Finished';
      } else {
        update();
        status.textContent = 'Fallback';
      }
    } finally {
      button.disabled = false;
    }
  });
</script>
</html>

Result

Initially: Ready. First click moves the blue square 160px right; the next click returns it. After completion: Finished on the supported path, otherwise Fallback.

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