MDN The view-transition-classCSS property provides the selected elements with one or more identifying classes (custom-idents), providing an additional method of styling the view transitions for those elements.
Live previewExample from MDN
/* Each element must have a unique view-transition-name */#card1 { view-transition-name: card-1;}#card2 { view-transition-name: card-2;}#card3 { view-transition-name: card-3;}/* But they can all share the same view-transition-class */.card { view-transition-class: card;}/* This single rule applies to all three cards' transitions */::view-transition-group(.card) { animation-duration: 0.5s; animation-timing-function: ease-in-out;}
MDN The view-transition-nameCSS property specifies the view transition snapshot that selected elements will participate in. This enables you to animate those elements separately from the rest of the page, which uses the default cross-fade animation during a view transition. You can then define custom animation styles for these elements.
<main class="match-element-applied"> <ul> <li> <h2><a href="#">HTML</a></h2> <h3>HyperText Markup Language</h3> <p> HyperText Markup Language (HTML) is the most basic building block of the web. It defines the meaning and structure of web content. HTML provides the fundamental building blocks for structuring web documents and apps. </p> </li> <li> <h2><a href="#">CSS</a></h2> <h3>Cascading Style Sheets</h3> <p> Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media. </p> </li> <li> <h2><a href="#">SVG</a></h2> <h3>Scalable Vector Graphics</h3> <p> Scalable Vector Graphics (SVG) is an XML-based markup language for describing two-dimensional based vector graphics. </p> </li> <li> <h2><a href="#">JS</a></h2> <h3>JavaScript</h3> <p> JavaScript (JS) is the web's native programming language. JavaScript is a lightweight, interpreted (or just-in-time compiled) programming language with first-class functions. While it is most well-known as the scripting language for web pages, many non-browser environments, such as Node.js, also use it. </p> </li> </ul> <article></article></main><form> <label for="match-element-checkbox"> Apply <code>match-element</code> to list items? </label> <input type="checkbox" id="match-element-checkbox" checked /></form>
const mainElem = document.querySelector("main");let prevElem;let checkboxElem = document.querySelector("input");// View transition codefunction updateActiveItem(event) { // Get the list item that contains the clicked link const clickedElem = event.target.parentElement.parentElement; // Set the active-item class on the list item clickedElem.className = "active-item"; // Keep track of the previous item that was clicked, if any. // Remove the active-item class from the previous item so that only // one list item is placed over the <article> at any one time if (prevElem === clickedElem) { prevElem.className = ""; prevElem = undefined; } else if (prevElem) { prevElem.className = ""; prevElem = clickedElem; } else { prevElem = clickedElem; }}mainElem.addEventListener("click", (event) => { event.preventDefault(); // Prevent iframe from scrolling when clicked // Do nothing unless a link is clicked inside the <main> element if (event.target.tagName !== "A") { return; } // Run updateActiveItem() on its own if view transitions are not supported if (!document.startViewTransition) { updateActiveItem(event); } else { // Run updateActiveItem() via startViewTransition() const transition = document.startViewTransition(() => updateActiveItem(event), ); }});// Toggle the class on <main> to control whether or not match-element is appliedcheckboxElem.addEventListener("change", () => { mainElem.classList.toggle("match-element-applied");});
Syntax
none | <custom-ident>
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition
Initial
none
Applies to
all elements
Inherited
no
Percentages
n/a
Computed value
as specified
Canonical order
per grammar
Animation type
discrete
Browser support
First browser version supporting view-transition-name
Chrome
111
Edge
111
Firefox
144
Safari
18
Chrome Android
111
Safari iOS
18
First version with support, from MDN browser-compat-data.
MDN The view-transition-scopeCSS property enables the discoverability of elements with view-transition-name values set on them (and therefore the creation of view transition snapshots) to be isolated to a specific element subtree.
<button>Update DOM</button><section> <div class="change-me"><span>I can change</span></div> <div class="change-me"> <span>I can change</span> <div class="change-me"><span>I can change</span></div> </div> <div class="change-me"><span>I can change</span></div></section>
const btn = document.querySelector("button");const divs = document.querySelectorAll("div");function updateDivs() { divs.forEach((div) => { if (div.firstElementChild.textContent === "I can change") { div.firstElementChild.textContent = "I have changed"; div.style.color = "white"; div.style.backgroundColor = "black"; } else { div.firstElementChild.textContent = "I can change"; div.style.color = "black"; div.style.backgroundColor = "white"; } });}btn.addEventListener("click", handleClick);function handleClick(e) { if (!document.startViewTransition) { updateDivs(); return; } document.startViewTransition(() => { updateDivs(); });}
Syntax
none | all
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition
Initial
none
Applies to
all elements
Inherited
no
Percentages
n/a
Computed value
as specified
Canonical order
per grammar
Animation type
discrete
Browser support
First browser version supporting view-transition-scope
Chrome
147
Edge
147
Firefox
No
Safari
No
Chrome Android
147
Safari iOS
No
First version with support, from MDN browser-compat-data.
MDN The @view-transitionCSSat-rule is used to opt in the current and destination documents to undergo a view transition, in the case of a cross-document navigation.
Syntax
@view-transition { <declaration-list> }
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support
First browser version supporting @view-transition
Chrome
126
Edge
126
Firefox
No
Safari
18.2
Chrome Android
126
Safari iOS
18.2
First version with support, from MDN browser-compat-data.
Spec The ::view-transition pseudo-element is a fully styleable pseudo-element that is also a pseudo-element root. If its originating element is the document’s document element, its containing block is the snapshot containing block.
MDN The ::view-transitionCSSpseudo-element represents the root of the view transitions overlay, which contains all view transition snapshot groups and sits over the top of all other page content.
Syntax
::view-transition
Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support
First browser version supporting ::view-transition
Chrome
109
Edge
109
Firefox
144
Safari
18
Chrome Android
109
Safari iOS
18
First version with support, from MDN browser-compat-data.
Spec The ::view-transition-group-children() pseudo-element is created when mandated by the view-transition-group property on either the element itself or on its contained element. It serves as a container for descendant view-transition-group() pseudo-elements. By default, it is sized to the same size as the corresponding view-transition-group() pseudo element. By default, it has a transparent border that matches the size and shape of the border on the element that caused this structure to be created.
Browser support
First browser version supporting ::view-transition-group-children()
Chrome
140
Edge
140
Firefox
No
Safari
No
Chrome Android
140
Safari iOS
No
First version with support, from MDN browser-compat-data.
Spec The ::view-transition-group() pseudo-element is a named view transition pseudo-element that represents a matching named view transition capture. A ::view-transition-group() pseudo-element is generated for each view transition name as a child of the ::view-transition pseudo-element, and contains a corresponding ::view-transition-image-pair().
MDN The ::view-transition-group()CSSpseudo-element represents a single view transition snapshot group.
Browser support
First browser version supporting ::view-transition-group()
Chrome
109
Edge
109
Firefox
144
Safari
18
Chrome Android
109
Safari iOS
18
First version with support, from MDN browser-compat-data.
Spec The ::view-transition-image-pair() pseudo-element is a named view transition pseudo-element that represents a pair of corresponding old/new view transition captures. This pseudo-element is a child of the corresponding ::view-transition-group() pseudo-element and contains a corresponding ::view-transition-old() pseudo-element and/or a corresponding ::view-transition-new() pseudo-element (in that order).
MDN The ::view-transition-image-pair()CSSpseudo-element represents a container for a view transition's "old" and "new" view states — before and after the transition.
Browser support
First browser version supporting ::view-transition-image-pair()
Chrome
109
Edge
109
Firefox
144
Safari
18
Chrome Android
109
Safari iOS
18
First version with support, from MDN browser-compat-data.
Spec The ::view-transition-new() pseudo-element (like the analogous ::view-transition-old() pseudo-element) is an empty named view transition pseudo-element that represents a visual snapshot of the “new” state as a replaced element; it is omitted if there’s no “new” state to represent. Each ::view-transition-new() pseudo-element is a child of the corresponding ::view-transition-image-pair() pseudo-element.
MDN The ::view-transition-new()CSSpseudo-element represents the "new" view state of a view transition — a snapshot live representation of the state after the transition.
Browser support
First browser version supporting ::view-transition-new()
Chrome
109
Edge
109
Firefox
144
Safari
18
Chrome Android
109
Safari iOS
18
First version with support, from MDN browser-compat-data.
Spec The ::view-transition-old() pseudo-element is an empty named view transition pseudo-element that represents a visual snapshot of the “old” state as a replaced element; it is omitted if there’s no “old” state to represent. Each ::view-transition-old() pseudo-element is a child of the corresponding ::view-transition-image-pair() pseudo-element.
MDN The ::view-transition-old()CSSpseudo-element represents the "old" view state of a view transition — a static snapshot of the old view, before the transition.
Browser support
First browser version supporting ::view-transition-old()
Chrome
109
Edge
109
Firefox
144
Safari
18
Chrome Android
109
Safari iOS
18
First version with support, from MDN browser-compat-data.
Spec The :active-view-transition pseudo-class applies to the root element of the document, if it has an active view transition.
MDN The :active-view-transitionCSSpseudo-class matches the root element of a document when a view transition is in progress (active) and stops matching once the transition has completed.
Spec The :active-view-transition-type() pseudo-class applies to the root element of the document, if it has a matching active view transition. It has the following syntax definition:
MDN The functional :active-view-transition-type()CSSpseudo-class matches elements when a view transition with one or more specific types is in progress (is active) and stops matching once the view transition has completed.
<p>This is my first piece of content. I hope you like it!</p><div> <button id="backwards">Backwards</button> <button id="forwards">Forwards</button></div>
const backBtn = document.getElementById("backwards");const fwdBtn = document.getElementById("forwards");const content = document.querySelector("p");const first = "This is my first piece of content. I hope you like it!";const second = "This is my second piece of content. Is it better than the first?";backBtn.addEventListener("click", changeContent);fwdBtn.addEventListener("click", changeContent);function changeContent(e) { const type = e.target === backBtn ? "backwards" : "forwards"; document.startViewTransition({ update() { content.textContent === first ? (content.textContent = second) : (content.textContent = first); }, types: [type], });}
Browser support
First browser version supporting :active-view-transition-type()
Chrome
125
Edge
125
Firefox
147
Safari
18.2
Chrome Android
125
Safari iOS
18.2
First version with support, from MDN browser-compat-data.