Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:active-view-transition-type() — select by transition type

This pseudo-class matches the element that scopes an active view transition if the transition has at least one of the specified types.

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

Syntax

:active-view-transition-type(<custom-ident>#)

:active-view-transition-type() matches the element that scopes an active view transition when the transition has at least one listed type. For a document-scoped transition, that element is the document root. For an element-scoped transition, it is the element that scopes the transition. The pseudo-class does not directly select animated descendants.

Arguments are comma-separated <custom-ident> identifiers: :active-view-transition-type(demo, reverse) means OR. Chaining :active-view-transition-type(demo):active-view-transition-type(reverse) requires both types. One pseudo-class has specificity (0,1,0).

Types can be supplied through startViewTransition({ update, types }), changed through ViewTransition.types, or declared with the types descriptor in @view-transition. They are not view-transition-name names. Unlike :active-view-transition, this pseudo-class requires a matching type; without an active transition, it does not match.

The definition comes from an evolving draft. The example requires verification in the target browser.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Match a view transition by type</title>
  <style>
    :root:active-view-transition-type(demo) #state { color: teal; }
  </style>
</head>
<body>
  <main><p id="state">Before update</p></main>
  <script>
    (() => {
      const selector = ':active-view-transition-type(demo)';
      if (!CSS.supports(`selector(${selector})`) ||
          typeof document.startViewTransition !== 'function' ||
          typeof ViewTransition === 'undefined' || !('types' in ViewTransition.prototype)) {
        console.log('Typed view transition selector: unsupported');
        return;
      }
      const root = document.documentElement;
      const state = document.getElementById('state');
      const before = root.matches(selector);
      const transition = document.startViewTransition({
        update: () => { state.textContent = 'After update'; },
        types: ['demo']
      });
      // Skipping rejects ready; this test checks selector state, not rendering.
      transition.ready.catch(() => {});
      const demo = root.matches(selector);
      const other = root.matches(':active-view-transition-type(other)');
      transition.skipTransition();
      const after = root.matches(selector);
      console.log(`Typed view transition selector: supported\nBefore: ${before}\nActive demo: ${demo}\nActive other: ${other}\nAfter skip: ${after}`);
    })();
  </script>
</body>
</html>

Result

Typed view transition selector: supported
Before: false
Active demo: true
Active other: false
After skip: false

The example tests matching only on the document root for a document-scoped transition. 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