CSS Portal

:active-view-transition-type() CSS Pseudo Class

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

Description

The :active-view-transition-type() pseudo-class is used to target elements while a View Transition of a specific type is currently active. It allows developers to conditionally apply styles during a named view transition, enabling fine-grained visual control over animations that occur when the DOM changes (such as page navigation, content swaps, or UI state updates).

This pseudo-class is part of the CSS View Transitions API and works in conjunction with JavaScript-triggered transitions (for example, using document.startViewTransition()).

What it does

The :active-view-transition-type() pseudo-class matches an element only while a view transition with a given type name is running. Once the transition finishes, the selector no longer applies.

This makes it useful for:

  • Styling elements differently during navigation animations
  • Adjusting layout or visibility during transitions
  • Applying motion-aware visual feedback

The value inside the parentheses must match the transition type defined when the transition is started in JavaScript.

Example: Styling during a navigation transition

:active-view-transition-type(navigation) {
  cursor: progress;
}

This applies while a transition of type navigation is active.

Example with a specific element

main:active-view-transition-type(page-change) {
  opacity: 0.8;
}

Here, the <a href="/html-tags/tag-main.php">main</a> element is slightly faded while the page-change transition is running.

Using with view transition pseudo-elements

You can combine it with view transition pseudo-elements such as ::view-transition-group() to control how content animates during a transition:

:active-view-transition-type(theme-switch)
::view-transition-group(root) {
  animation-duration: 600ms;
}

This example adjusts animation timing only while the theme-switch transition is active.

Example with JavaScript trigger

document.startViewTransition(() => {
  document.body.classList.toggle("dark");
}, { types: ["theme-switch"] });

Then in CSS:

:active-view-transition-type(theme-switch) {
  background-color: black;
}

Common use cases

  • Theme switching (light ↔ dark)
  • Page navigation effects
  • Modal or layout transitions
  • SPA-style content replacement

Notes & limitations

  • Only works while a view transition is actively running
  • Requires browser support for the View Transitions API
  • Does not persist styles after the transition ends
  • Must match the exact transition type name

Syntax

:active-view-transition-type(<custom-ident>#) {
  /* ... */
}

Values

  • <custom-ident>One or more comma-separated <custom-ident> values representing the choice of types that can be applied to the active view transition for this selector to match.

Example

<nav>
<button id="nextBtn">Go to Next Page</button>
<button id="backBtn">Go Back</button>
</nav>

<main class="content">
<h1>Dynamic Transitions</h1>
<p>The animation style changes based on which button you click.</p>
</main>
<script>
const nextBtn = document.querySelector('#nextBtn');
const backBtn = document.querySelector('#backBtn');

nextBtn.addEventListener('click', () => {
// Trigger transition with the 'forward' type
document.startViewTransition({
update: () => updateDOMContent('next'),
types: ['forward']
});
});

backBtn.addEventListener('click', () => {
// Trigger transition with the 'backward' type
document.startViewTransition({
update: () => updateDOMContent('back'),
types: ['backward']
});
});

function updateDOMContent(direction) {
document.querySelector('h1').textContent = `Moved ${direction}`;
}
</script>
/* Default transition behavior */
::view-transition-group(root) {
animation-duration: 0.5s;
}

/* Slide left when the type is 'forward' */
html:active-view-transition-type(forward)::view-transition-old(root) {
animation: slide-out-to-left 0.5s ease-in-out;
}
html:active-view-transition-type(forward)::view-transition-new(root) {
animation: slide-in-from-right 0.5s ease-in-out;
}

/* Slide right when the type is 'backward' */
html:active-view-transition-type(backward)::view-transition-old(root) {
animation: slide-out-to-right 0.5s ease-in-out;
}
html:active-view-transition-type(backward)::view-transition-new(root) {
animation: slide-in-from-left 0.5s ease-in-out;
}

/* Keyframes for the animations */
@keyframes slide-in-from-right {
from { transform: translateX(100%); }
}
@keyframes slide-out-to-left {
to { transform: translateX(-100%); }
}
@keyframes slide-in-from-left {
from { transform: translateX(-100%); }
}
@keyframes slide-out-to-right {
to { transform: translateX(100%); }
}

Browser Support

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

This psuedo class 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!