GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

`:active-view-transition` CSS pseudo-class

The :active-view-transition CSS pseudo-class matches the root element of a document when a view transition is in progress (active) and stops matching once the transition has completed.

The **`:active-view-transition`** [CSS](/docs/Web/CSS) [pseudo-class](/docs/Web/CSS/Reference/Selectors/Pseudo-classes) matches the root element of a document when a [view transition](/docs/Web/API/View_Transition_API#concepts_and_usage) is in progress (_active_) and stops matching once the transition has completed.

## Syntax

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

## Examples

### Styling an active view transition

This example extends the [Basic view transition example](/docs/Web/API/Document/startViewTransition#basic_usage) on the `startViewTransition` page.

```html
<main>
<section class="color">
<h2>Color is changing!</h2>
</section>
<button id="change-color">Change Color</button>
</main>
```

A `<h2>` element initially has a `display: none` style, and this is overwritten using the `:active-view-transition` pseudo-class setting the `<h2>` style to `display: block`.
The button is hidden using `visibility: hidden`, when the view transition is in progress:

```css hidden
html {
--bg: indigo;
}
main {
display: flex;
flex-direction: column;
gap: 5px;
}
section {
background-color: var(--bg);
height: 60px;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
}
::view-transition-group(root) {
animation-duration: 2s;
}
```

```css
h2 {
display: none;
color: white;
}
:root:active-view-transition h2 {
display: block;
}
:root:active-view-transition button {
visibility: hidden;
}
```

```js hidden
const colors = ["darkred", "darkslateblue", "darkgreen"];
const colBlock = document.querySelector(".color");
let count = 0;
const updateColor = () => {
colBlock.style = `--bg: ${colors[count]}`;
count = count !== colors.length - 1 ? ++count : 0;
};
const changeColor = () => {
if (!document.startViewTransition) {
updateColor();
return;
}
const transition = document.startViewTransition(() => {
updateColor();
});
};
const changeColorButton = document.querySelector("#change-color");
changeColorButton.addEventListener("click", changeColor);
changeColorButton.addEventListener("keypress", changeColor);
```

100%

## Specifications

## Browser compatibility

## See also

- :active-view-transition-type() pseudo-class
- [`startViewTransition()`](/docs/Web/API/Document/startViewTransition) method
- Document.activeViewTransition
- [View Transition API](/docs/Web/API/View_Transition_API)
- [Using the View Transition API](/docs/Web/API/View_Transition_API/Using)
- [Using view transition types](/docs/Web/API/View_Transition_API/Using_types)

source: MDN Web Docs mirror · page

Cite this

"`:active-view-transition` CSS pseudo-class". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:active-view-transition

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·