CSS Portal

:active-view-transition 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 pseudo-class represents an element while it is actively participating in a View Transition animation, as defined by the View Transitions API. It allows you to apply temporary styles only during the moment a transition is running, making it useful for fine-tuning animations, suppressing layout shifts, or visually synchronizing UI changes when navigating or updating content.

What :active-view-transition does

The :active-view-transition pseudo-class becomes active only while a view transition is in progress - from the moment the transition starts until it finishes. Outside of that window, the selector does nothing.

It is typically used alongside the View Transitions API, especially when using document.startViewTransition() or when navigation triggers a transition automatically.

Unlike persistent selectors, this pseudo-class is ephemeral - it exists only during the animation lifecycle.

Common use cases

  • Temporarily disabling animations during transitions
  • Preventing layout shifts
  • Adjusting opacity, visibility, or transforms during transitions
  • Fine-tuning how elements behave while snapshots are animating

Basic syntax

:active-view-transition {
  /* styles applied only during the transition */
}

Example: Reducing motion during a transition

:active-view-transition {
  animation: none;
  transition: none;
}

This prevents nested animations from interfering with the view transition animation itself.

Example: Targeting elements during a transition

main:active-view-transition {
  opacity: 0.95;
}

Here, the <code><a href="/html-tags/tag-main.php">main</a></code> element slightly fades while the transition is active.

Using with View Transition pseudo-elements

You’ll often see :active-view-transition used together with view-transition pseudo-elements such as ::view-transition-group() or ::view-transition-old(). These allow styling of snapshots taken before and after DOM updates.

Example:

:active-view-transition ::view-transition-old(root) {
  opacity: 0;
}

:active-view-transition ::view-transition-new(root) {
  opacity: 1;
}

This creates a simple fade-in effect during the transition.

Example with JavaScript trigger

<button id="swap">Swap Content</button>
<div id="content">Hello</div>
:active-view-transition #content {
  filter: blur(2px);
}
document.getElementById("swap").onclick = () => {
  document.startViewTransition(() => {
    document.getElementById("content").textContent = "Goodbye";
  });
};

During the transition, the content blurs briefly, then resolves when the transition ends.

Syntax

:root:active-view-transition ... {
  /* ... */
}

Example

<body>

<header id="main-header">
<h1>View Transition Demo</h1>
<button id="theme-button">Toggle Dark Mode</button>
</header>

<script>
const btn = document.querySelector('#theme-button');

btn.addEventListener('click', () => {
// Check if the browser supports the API
if (!document.startViewTransition) {
document.body.classList.toggle('dark-mode');
return;
}

// Trigger the transition
document.startViewTransition(() => {
document.body.classList.toggle('dark-mode');
});
});
</script>
</body>
/* Basic Styles */
body {
font-family: sans-serif;
transition: background-color 0.3s;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.dark-mode {
background-color: #1a1a1a;
color: white;
}

/* 1. Using :active-view-transition */
/* This selector targets the document only while the transition is moving */
html:active-view-transition {
outline: 5px solid #3498db;
}

/* 2. Customizing the transition behavior */
/* We can use the pseudo-class to change how the snapshots look */
html:active-view-transition-type(reload) {
/* Specific styles for reload types if defined */
}

/* Example of modifying the animation while active */
:root:active-view-transition ::view-transition-old(root),
:root:active-view-transition ::view-transition-new(root) {
animation-duration: 0.8s;
}

/* Visual cue to see the transition layers clearly */
html:active-view-transition ::view-transition-group(root) {
border: 2px dashed red;
}

Browser Support

The following information will show you the current browser support for the CSS :active-view-transition 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: 1st January 2026

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