CSS view-transition-class Property
The CSS view-transition-class property assigns one or more reusable class identifiers to an element's view transition representation.
These identifiers allow multiple view transition pseudo-elements to share animation styles without requiring separate rules for every transition name. The property works with view-transition-name and the ::view-transition-* pseudo-elements to customize transitions between document states or pages.
Unlike ordinary HTML classes, view transition classes are assigned through CSS and are used to match generated view transition pseudo-elements. They do not add class names to the element's HTML class attribute.
view-transition-class Syntax
The view-transition-class property accepts the keyword none or one or more space-separated custom identifiers.
Basic Syntax
.card {
view-transition-class: card;
}
Default Value
.card {
view-transition-class: none;
}
Multiple Classes
.card {
view-transition-class: card fade;
}
With a Transition Name
.card {
view-transition-name: card-one;
view-transition-class: card;
}
CSS-Wide Keywords
.card {
view-transition-class: initial;
}
.card {
view-transition-class: inherit;
}
.card {
view-transition-class: unset;
}
.card {
view-transition-class: revert;
}
.card {
view-transition-class: revert-layer;
}
Invalid Values
.card {
view-transition-class: "card";
}
.card {
view-transition-class: .card;
}
.card {
view-transition-class: card, fade;
}
.card {
view-transition-class: none fade;
}
Class identifiers are unquoted CSS identifiers. Do not include a leading period, separate them with commas, or combine none with class names.
Note: Unlike view-transition-name, class identifiers do not have to be unique among elements participating in a view transition.
Property Values
| Value | Description |
|---|---|
none |
Assigns no view transition classes. This is the initial value. |
<custom-ident> |
Assigns a custom class identifier to the element's view transition representation. |
<custom-ident> <custom-ident> |
Assigns multiple space-separated class identifiers to the same view transition representation. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | No |
| Applies to | All elements |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Shorthand | None |
| Specification | CSS View Transitions Module Level 2 |
Note: The property does not create a view transition by itself. It supplies class identifiers that can be used when an element participates in an active view transition.
How It Works
During a view transition, the browser captures the relevant old and new visual states and creates a temporary pseudo-element tree to animate between them.
The view-transition-class property allows several independently named transition groups to share styles through class-based pseudo-element selectors.
Step 1: Create Elements
<div class="card card-one">First Card</div>
<div class="card card-two">Second Card</div>
Step 2: Assign Unique Transition Names
.card-one {
view-transition-name: first-card;
}
.card-two {
view-transition-name: second-card;
}
Each independently captured element needs its own transition name.
Step 3: Assign a Shared Transition Class
.card {
view-transition-class: card;
}
Both elements now use the same view transition class identifier.
Step 4: Style the Generated Pseudo-Elements
::view-transition-group(.card) {
animation-duration: 500ms;
}
The selector matches transition groups assigned the card class.
Step 5: Start a View Transition
document.startViewTransition(() => {
document.querySelector(".card-one").classList.toggle("expanded");
});
The browser captures the old state, performs the DOM update, captures the new state, and animates the transition.
Important Distinction
The transition name identifies an individual transition group. The transition class allows multiple groups to share styling rules.
The none Value
The none value specifies that no view transition class identifiers are assigned.
Syntax
.card {
view-transition-class: none;
}
Default Behavior
The initial value is none. Elements do not receive view transition classes unless the property is explicitly declared.
Removing a Class Assignment
.card {
view-transition-class: card;
}
.card.no-shared-style {
view-transition-class: none;
}
The second rule removes the view transition class assignment for the selected element.
Does Not Remove the Transition Name
.card {
view-transition-name: card-one;
view-transition-class: none;
}
The element can still participate in a named view transition. It simply has no class identifiers for class-based transition selectors.
When to Use It
Use none when an element should retain its individual transition behavior without receiving shared class-based styles.
Custom Class Identifiers
View transition classes use CSS custom identifiers. These are unquoted names that can be referenced by view transition pseudo-element selectors.
Valid Identifiers
.card {
view-transition-class: card;
}
.image {
view-transition-class: image-reveal;
}
.panel {
view-transition-class: panel;
}
Invalid Identifiers
.card {
view-transition-class: "card";
}
.image {
view-transition-class: .image;
}
Quotation marks and the selector period are not part of the property value.
Using Identifiers in Selectors
.card {
view-transition-class: card;
}
::view-transition-group(.card) {
animation-duration: 400ms;
}
The class identifier is written as card in the property value and as .card inside the pseudo-element selector.
Names Are Case-Sensitive
.card {
view-transition-class: Card;
}
::view-transition-group(.card) {
animation-duration: 400ms;
}
The class identifier Card does not match the lowercase .card selector.
Class Names Are Reusable
Multiple elements can share the same view transition class. This is the primary purpose of the property.
Naming Recommendations
Use descriptive identifiers such as card, image, fade, or slide to describe the transition group or intended animation style.
Multiple View Transition Classes
An element can receive multiple view transition class identifiers using a space-separated list.
Two Classes
.card {
view-transition-class: card fade;
}
Three Classes
.card {
view-transition-class: card fade featured;
}
Matching Individual Classes
::view-transition-group(.card) {
animation-duration: 500ms;
}
::view-transition-new(.fade) {
animation-timing-function: ease-out;
}
Each selector can match transition pseudo-elements associated with its class identifier.
Combining Shared and Specialized Styles
.card {
view-transition-class: card;
}
.card.featured {
view-transition-class: card featured;
}
::view-transition-group(.card) {
animation-duration: 400ms;
}
::view-transition-group(.featured) {
animation-duration: 700ms;
}
All cards share the general rule, while featured cards receive the additional rule. Normal CSS cascade rules determine which duration applies.
Space-Separated, Not Comma-Separated
.card {
view-transition-class: card fade;
}
Do not separate class identifiers with commas.
Important Consideration
Multiple class identifiers do not create multiple transition groups. They provide multiple ways to select and style the same generated transition representation.
Relationship to view-transition-name
The view-transition-name and view-transition-class properties serve different purposes.
Unique Transition Names
.card-one {
view-transition-name: card-one;
}
.card-two {
view-transition-name: card-two;
}
Transition names identify independently captured visual elements. Within a captured document state, the same non-none transition name cannot be assigned to multiple participating elements.
Shared Transition Classes
.card-one,
.card-two {
view-transition-class: card;
}
Both cards can share the same transition class without creating a name conflict.
Name-Based Selector
::view-transition-group(card-one) {
animation-duration: 600ms;
}
This selector targets the transition group named card-one.
Class-Based Selector
::view-transition-group(.card) {
animation-duration: 600ms;
}
This selector targets transition groups assigned the card class.
Using Both Selectors
::view-transition-group(.card) {
animation-duration: 400ms;
}
::view-transition-group(card-one) {
animation-duration: 700ms;
}
General class-based styling and individual name-based styling can be combined. The CSS cascade determines which declarations apply when rules overlap.
Important Consideration
Assigning a transition class does not automatically assign a transition name. An element must participate in a view transition for its class identifiers to be useful.
View Transition Pseudo-Elements
During a view transition, the browser creates a temporary pseudo-element tree containing representations of the old and new document states.
View transition classes can be used with pseudo-element selectors that accept a transition name or class selector.
::view-transition
::view-transition {
pointer-events: none;
}
Represents the root of the generated view transition pseudo-element tree. This selector does not accept a transition class argument.
::view-transition-group()
::view-transition-group(.card) {
animation-duration: 500ms;
}
Selects transition groups associated with the specified class.
::view-transition-image-pair()
::view-transition-image-pair(.card) {
isolation: isolate;
}
Selects the image-pair pseudo-elements associated with the class.
::view-transition-old()
::view-transition-old(.card) {
animation-timing-function: ease-in;
}
Selects old-state snapshots associated with the class.
::view-transition-new()
::view-transition-new(.card) {
animation-timing-function: ease-out;
}
Selects new-state snapshots associated with the class.
Wildcard Selectors
::view-transition-group(*) {
animation-duration: 400ms;
}
The wildcard selects all generated transition groups, regardless of their names or classes.
Class vs. Name Selection
::view-transition-new(card-one) {
animation-duration: 600ms;
}
::view-transition-new(.card) {
animation-timing-function: ease-out;
}
The first rule selects a specific named transition, while the second applies to all matching class-associated transitions.
Shared Animation Styles
One of the main advantages of view-transition-class is the ability to reuse animation rules across several independently named transitions.
Without Shared Classes
::view-transition-group(card-one),
::view-transition-group(card-two),
::view-transition-group(card-three) {
animation-duration: 500ms;
}
Each transition name must be listed explicitly.
With a Shared Class
.card {
view-transition-class: card;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
All participating cards assigned the card class can share the same rule.
Shared Fade Animation
@keyframes shared-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
::view-transition-new(.fade) {
animation: 400ms ease-out both shared-fade-in;
}
Shared Slide Animation
@keyframes shared-slide-in {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
::view-transition-new(.slide) {
animation: 500ms ease-out both shared-slide-in;
}
Combining Effects
.card {
view-transition-class: card fade;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
::view-transition-new(.fade) {
animation-timing-function: ease-out;
}
Important Consideration
Custom animations on view transition pseudo-elements can override the browser's default transition animations. Test the results carefully, particularly when elements change size or position.
Same-Document View Transitions
Same-document view transitions animate visual changes made within a single document, such as expanding cards, changing layouts, or updating content.
They are commonly started with the document.startViewTransition() method.
HTML Example
<button type="button" id="toggle-layout">Change Layout</button>
<div class="card-grid">
<div class="card card-one">First Card</div>
<div class="card card-two">Second Card</div>
</div>
CSS Example
.card-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
.card-grid.stacked {
grid-template-columns: 1fr;
}
.card-one {
view-transition-name: first-card;
}
.card-two {
view-transition-name: second-card;
}
.card {
view-transition-class: card;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
JavaScript Example
const button = document.querySelector("#toggle-layout");
const grid = document.querySelector(".card-grid");
button.addEventListener("click", () => {
const update = () => grid.classList.toggle("stacked");
if (document.startViewTransition) {
document.startViewTransition(update);
} else {
update();
}
});
How It Works
The browser captures the old layout, updates the grid, and captures the new layout. Each card has a unique transition name, while both share the card transition class.
Fallback Behavior
If the View Transition API is unavailable, the JavaScript updates the layout without starting a view transition.
Important Consideration
Use unique transition names for independently animated elements. Shared transition classes do not replace the need for distinct names.
Cross-Document View Transitions
View transitions can also animate navigation between eligible documents on the same origin when the browser supports cross-document view transitions.
For eligible same-origin navigations, both documents must opt in using the @view-transition at-rule.
Enable Navigation Transitions
@view-transition {
navigation: auto;
}
Assign Transition Names and Classes
.page-logo {
view-transition-name: site-logo;
view-transition-class: branding;
}
.page-heading {
view-transition-name: page-heading;
view-transition-class: heading;
}
Shared Transition Styles
::view-transition-group(.branding) {
animation-duration: 500ms;
}
::view-transition-new(.heading) {
animation-timing-function: ease-out;
}
Matching Elements Between Pages
When corresponding elements use matching transition names in the old and new documents, the browser can animate between their captured states.
Class-Based Styling
Transition classes provide reusable styling for groups of named transitions across participating pages.
Important Consideration
Cross-document transitions depend on browser support, navigation eligibility, and the required document opt-in. The view-transition-class property alone does not enable navigation transitions.
Inheritance
The view-transition-class property is not inherited. Child elements do not automatically receive the view transition classes assigned to their parents.
Parent Declaration
.parent {
view-transition-class: container;
}
Child Declaration
.parent .child {
view-transition-class: card;
}
The child uses its own class identifier.
Explicit Inheritance
.parent {
view-transition-class: container;
}
.parent .child {
view-transition-class: inherit;
}
The child explicitly inherits the parent's computed class identifiers.
Restore the Initial Value
.example {
view-transition-class: initial;
}
This restores the initial value of none.
Using unset
.example {
view-transition-class: unset;
}
Because the property is not inherited, unset behaves like initial.
Important Consideration
Explicit inheritance copies the class identifiers, not the parent's transition name. Each independently captured element still requires an appropriate transition name.
Practical Examples
Shared Card Transitions
.card {
view-transition-class: card;
}
.card-one {
view-transition-name: card-one;
}
.card-two {
view-transition-name: card-two;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
Shared Image Transitions
.gallery-image {
view-transition-class: gallery-image;
}
::view-transition-image-pair(.gallery-image) {
isolation: isolate;
}
Fade New Snapshots
.fade-element {
view-transition-class: fade;
}
::view-transition-new(.fade) {
animation-timing-function: ease-out;
}
Different Transition Durations
.card {
view-transition-class: card;
}
.card.featured {
view-transition-class: card featured;
}
::view-transition-group(.card) {
animation-duration: 400ms;
}
::view-transition-group(.featured) {
animation-duration: 700ms;
}
Shared Navigation Transitions
.navigation-item {
view-transition-class: navigation;
}
::view-transition-group(.navigation) {
animation-duration: 300ms;
}
Shared Heading Transitions
.page-heading {
view-transition-class: heading;
}
::view-transition-new(.heading) {
animation-timing-function: ease-out;
}
Multiple Style Categories
.card {
view-transition-class: card fade;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
::view-transition-new(.fade) {
animation-timing-function: ease-in-out;
}
Remove Shared Styling
.card.no-shared-transition {
view-transition-class: none;
}
This removes the shared class identifiers without necessarily removing the element's named view transition.
view-transition-class Example
This interactive example demonstrates how two cards can use different transition names while sharing the same view-transition-class value.
Click the button to switch between a two-column layout and a stacked layout. In supporting browsers, both cards animate using a shared transition duration.
HTML Example
<div class="transition-demo">
<button type="button" class="transition-button">Change Layout</button>
<div class="transition-grid">
<div class="transition-card first-card">First Card</div>
<div class="transition-card second-card">Second Card</div>
</div>
</div>
CSS Example
.transition-button {
margin-bottom: 15px;
padding: 10px 20px;
color: #fff;
background-color: #0066cc;
border: 0;
cursor: pointer;
}
.transition-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 15px;
}
.transition-grid.stacked {
grid-template-columns: 1fr;
}
.transition-card {
padding: 30px 15px;
background-color: #e5eef7;
border: 2px solid #0066cc;
border-radius: 6px;
text-align: center;
view-transition-class: demo-card;
}
.first-card {
view-transition-name: demo-first;
}
.second-card {
view-transition-name: demo-second;
}
::view-transition-group(.demo-card) {
animation-duration: 600ms;
}
@media (prefers-reduced-motion: reduce) {
::view-transition-group(.demo-card) {
animation-duration: 0.01ms;
}
}
JavaScript Example
const demo = document.querySelector(".transition-demo");
const button = demo.querySelector(".transition-button");
const grid = demo.querySelector(".transition-grid");
button.addEventListener("click", () => {
const update = () => grid.classList.toggle("stacked");
if (document.startViewTransition) {
document.startViewTransition(update);
} else {
update();
}
});
Understanding the Results
Each card has a unique view-transition-name, allowing the browser to track the cards independently during the layout change.
Shared Class Assignment
Both cards use view-transition-class: demo-card, so they can share class-based transition styling.
Shared Animation Duration
The ::view-transition-group(.demo-card) selector applies the same animation duration to both transition groups.
Starting the Transition
The button uses document.startViewTransition() to animate the change between the grid and stacked layouts.
Fallback Behavior
If the View Transition API is unsupported or reduced motion is requested, the layout changes without starting the transition.
Experiment With the Duration
::view-transition-group(.demo-card) {
animation-duration: 1000ms;
}
Both cards now use a longer transition duration.
Experiment With Individual Styling
::view-transition-group(demo-first) {
animation-duration: 300ms;
}
This targets the first card by its unique transition name rather than the shared class.
Experiment With Another Class
.second-card {
view-transition-class: demo-card featured;
}
::view-transition-group(.featured) {
animation-duration: 900ms;
}
The second card receives an additional class that can be used for specialized styling.
Accessibility Considerations
The view-transition-class property controls styling of generated transition pseudo-elements. It does not change document semantics, reading order, or the accessibility tree.
Respect Reduced Motion Preferences
Provide a reduced-motion alternative for users who prefer less animation.
@media (prefers-reduced-motion: reduce) {
::view-transition-group(.card) {
animation-duration: 0.01ms;
}
}
Avoid Excessive Movement
Large translations, rapid scaling, and repeated transitions can be distracting or uncomfortable.
Keep Content Accessible
Important information should remain available before, during, and after a transition.
Maintain Keyboard Navigation
View transitions should not interfere with keyboard focus or prevent users from interacting with the updated document.
Avoid Unnecessary Delays
Long transitions can slow the perceived response to user actions.
Test Without Transitions
Verify that layout changes and navigation remain understandable when the View Transition API is unsupported or disabled.
Preserve Focus When Updating Content
When DOM updates replace interactive elements, manage focus appropriately so keyboard and assistive technology users can continue interacting with the page.
Common Mistakes
Using a Leading Period in the Property Value
.card {
view-transition-class: .card;
}
The property value uses card, not .card.
Using Quotation Marks
.card {
view-transition-class: "card";
}
Class identifiers are not strings.
Separating Classes With Commas
.card {
view-transition-class: card, fade;
}
Multiple class identifiers must be separated by spaces.
Combining none With Class Names
.card {
view-transition-class: none card;
}
The none keyword must be used alone.
Confusing Classes With Transition Names
Transition names identify individual groups, while transition classes provide reusable styling categories.
Using Duplicate Transition Names
Multiple independently captured elements cannot share the same transition name within a captured document state. Shared classes do not have this restriction.
Forgetting to Start a View Transition
The property does not automatically start transitions when the DOM changes.
Using the Wrong Pseudo-Element Selector
::view-transition-group(card) {
animation-duration: 500ms;
}
This selects a transition named card, not one assigned the card class. Use ::view-transition-group(.card) for class matching.
Assuming Classes Modify HTML
The property does not add names to the element's HTML class attribute.
Ignoring Browser Support
Provide fallbacks because support for view transition classes varies among browsers.
Ignoring Reduced Motion Preferences
Reduce or disable substantial animation when the user requests reduced motion.
Important Considerations
Keep the following points in mind when using view-transition-class:
- The property assigns reusable class identifiers to view transition representations.
- It is part of CSS View Transitions Module Level 2.
- Its initial value is
none. - The property is not inherited.
- It accepts one or more custom identifiers.
- Multiple identifiers are separated by spaces.
- Class identifiers do not include a leading period in the property value.
- Class selectors use a leading period inside view transition pseudo-element selectors.
- Class identifiers are case-sensitive.
- Class identifiers can be shared among multiple elements.
- Class identifiers do not have to be unique.
- Transition names identify independently captured elements.
- Transition names must not conflict within a captured document state.
- Transition classes do not replace transition names.
- The property does not create a view transition by itself.
- Same-document transitions can be started using
document.startViewTransition(). - Eligible cross-document transitions require appropriate browser support and document opt-in.
- The property can style multiple transition groups through shared selectors.
- Class-based selectors can target transition groups, image pairs, and old or new snapshots.
- The root
::view-transitionpseudo-element does not accept a class argument. - Name-based and class-based selectors can be combined.
- Normal CSS cascade rules apply when transition styles overlap.
- Multiple class identifiers do not create multiple transition groups.
- The property does not modify an element's HTML class attribute.
- The property does not change document semantics or reading order.
- Custom transition animations can override default browser animations.
- Test transitions involving changes in element size and position.
- Provide fallbacks for unsupported browsers.
- Respect reduced-motion preferences.
- Keep important content accessible throughout transitions.
- Test keyboard focus behavior after DOM updates.
Browser Support
The CSS view-transition-class property has limited availability and is not supported consistently across all browsers.
Support depends on the browser's implementation of view transition classes and class-based view transition pseudo-element selectors. Older implementations of the View Transition API may support view-transition-name without supporting view-transition-class.
For current compatibility information, visit Can I Use? and search for view-transition-class.
Standard Declaration
.card {
view-transition-name: card-one;
view-transition-class: card;
}
Feature Detection
@supports (view-transition-class: card) {
.card {
view-transition-class: card;
}
::view-transition-group(.card) {
animation-duration: 500ms;
}
}
JavaScript Feature Detection
if (document.startViewTransition) {
document.startViewTransition(updateContent);
} else {
updateContent();
}
This checks whether the same-document View Transition API is available. It does not independently confirm support for view-transition-class.
Progressive Enhancement
Use ordinary DOM updates and layout styles as the baseline. Add view transition classes and animations only when the necessary features are supported.
Vendor Prefixes
The standard property uses the unprefixed view-transition-class name. Consult current browser documentation when supporting experimental implementations.
Testing Recommendations
Test class-based selectors, multiple class identifiers, same-document transitions, and reduced-motion behavior. Verify that the interface remains usable without view transitions.
Specifications
The view-transition-class property is defined in CSS View Transitions Module Level 2.
CSS View Transitions Module Level 2 - view-transition-class
The specification defines how class identifiers are associated with view transition representations and used by class-based pseudo-element selectors.
For additional documentation and examples, consult MDN Web Docs.
