View-transition-name - CSS Property

view-transition-name

Summary of characteristics of the view-transition-name property

Quick description
Associates a transition identifier with the targeted element.
Status
Standard
Applies to
All elements.
Usable for
HTML
Percentages
Not applicable.
Initial value
none
Inherited by default
No.
Discrète: during an animation, the view-transition-name property passes from one value to another without transition.
Single: single value (no order).
W3C Module
CSS View Transitions Module
Document status: CR (Candidate Recommendation)

(1) The animation of view-transition-name does not affect the ongoing transition.

Syntax diagram of view-transition-name.

view-transition-name - Syntax DiagramSyntax diagram of the view-transition-name CSS property. See stylescss.free.fr for details. none none id id auto autoview-transition-name:;view-transition-name:;
Syntax diagram of the view-transition-name property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

In the diagram, the term id is a freely chosen identifier.

Description of the view-transition-name property.

The property view-transition-name facilitates the implementation of View Transition by associating an identifier with the elements that need to be animated during the transition. Indeed, by default, the animation applies to the root of the document. The following examples allow you to visualize the usefulness of this property.

No display transition. The new elements abruptly replace the old ones.
Click on the image to see the rendering.
Note, on a portable device there is always by default a small transition effect.

Argine
Example without view transition

A 'fade' type view transition. In this case, applying the animation to the root element of the page (root) is not problematic: elements that are not changed appear unchanged.

Argine
Example of view transition

A more sophisticated view transition (rotation and fade). Applying this kind of animation to the root is not feasible.

Argine
Example of view transition

The property view-transition-name defines identifiers that can be used to apply a different animation to specific elements, and not to apply animation to the root.

Argine
Example of view transition
/* Association of identifiers with the title and image */ #title4 {view-transition-name:title4;} #image4 {view-transition-name:image4;} /* Application of animations based on identifiers */ ::view-transition-old(title4) {animation:zoom-old 2s;} ::view-transition-new(title4) {animation:zoom-new 2s;} ::view-transition-old(image4) {animation:rotation-old 2s;} ::view-transition-new(image4) {animation:rotation-new 2s;}

Note: on this page we also had to use the concept of transition type so that all animations do not start at the same time. The property view-transition-name only allows you to define animations specific to each element, but all these animations start at the same time.

To read more information about view transitions in general, see the tutorial on view transitions.


Other pages related to view transitions.

On view transitions.
Associates a transition identifier with the targeted element.
Targets the screenshot of the previous state, in the case of a view transition.
Targets the screenshot of the new state, in the case of a View Transition.
Allows applying identical styles to different display transitions.
Builds a hierarchy between pseudo-elements related to viewtransitions.
Multiple view transitions on the same page.
Targets the root of the document, during a view transition.
Targets the root of the document, during a view transition of a certain type.
View transitions from one document to another.
Enables or disables display transitions between pages. These transitions allow effects such as fades, slides, etc.

Values for view-transition-name.

  • view-transition-name: none;

    This is the default value: no transition ID is associated with the element.

  • view-transition-name: id;

    id is an identifier chosen by the developer. The only prohibited values are none and auto. This identifier can be reused by the pseudo-elements ::view-transition-new() and ::view-transition-old() for the definition of a specific animation on the element.

  • view-transition-name: auto;

    A transition identifier is automatically generated, most of the time from the item's ID.

    Introduced in level 2 of the specification, this value is not yet very well recognized.

  • view-transition-name: initial; (none) view-transition-name: inherit; view-transition-name: revert; view-transition-name: revertLayer; view-transition-name: unset;

    Links to the presentation of these different values: initial, inherit, revert, revert-layer, unset.

Animation of the view-transition-name property.

The property view-transition-name, which only accepts non-numeric values, has an animation of the discrete type: abrupt transition from one value to another.

Nevertheless, the result of an animation of this property is quite uncertain because view-transition-name only takes effect during a change on the page, either as a result of a user action or through a Javascript code.

Access the view-transition-name property via a program

Changing the identifier of elements subject to a view transition.

In other words, change the value of view-transition-name in JavaScript. Two codes are given below: the first manipulates the array of styles, with a syntax in kebab-case, the second uses a syntax closer to JavaScript object syntax (the property name is written in camel-case).

Javascript
let el = document.getElementById('id'); el.style['view-transition-name'] = 'example'; // or let el = document.getElementById('id'); el.style.viewTransitionName = 'example';

Retrieving the value of view-transition-name with Javascript.

The property must have been applied directly to the element itself via its style attribute, and not through a CSS selector. Here too, two syntaxes are possible. By the way, this code is the mirror of the previous one.

Javascript
let el = document.getElementById('id'); let value = el.style['view-transition-name']; // or let el = document.getElementById('id'); let value = el.style.viewTransitionName;

Retrieval of the computed value of view-transition-name}.

The computed value is the one that results from the cascade of inheritance: the value applied to the element via its style attribute or a CSS selector, if it is inherit, the value inherited from one of the parents, or failing that the initial value of the property (none in the case of view-transition-name). The computed value is defined in all cases.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('view-transition-name');

Changing the value of view-transition-name with JQuery.

JQuery also offers two syntaxes to modify the value of view-transition-name.

JQuery

$('#id').css('view-transition-name', 'example');
// or
$('#id').css('viewTransitionName', 'example');

Retrieving the calculated value of view-transition-name with JQuery.

And a syntax to retrieve the calculated value, much more compact than that of Javascript.

JQuery
let value = $('#id').css('view-transition-name');

Other code examples.

Other examples of Javascript and JQuery code regarding the manipulation of CSS styles are given on the page Javascript and CSS.

Test yourself.

The buttons below apply the entered value to the property view-transition-name and then display either the value as it was applied, or the computed value. In the case of this property, there will be no difference.

Browsers compatibility with view-transition-name.

Display transitions are well recognized by all recent browsers. Nevertheless, from one document to another, there are still incompatibilities.

Column 1
Support for on-page display transitions (not from page to page). Corresponding to level 1 of the specification.
Column 2
Supports page-to-page view transitions (level 2 of the specification).
Column 3
Supported by browsers for the property view-transition-name which allows applying a view transition to something other than the root (:root).

Notes:

(1) Disabled by default. Can be enabled by setting the flag dom.viewTransitions.enabled to TRUE.

1
View transitions
in the page
2
Display transitions
from one page to another
3
view-transition-name
property
Estimated overall support.
86%
42%
86%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Safari

Samsung Internet

Chrome

Edge

Firefox

Opéra

Chrome pour Androïd

Safari sur IOS

Androïd Brower

Firefox pour Androïd

KaiOS Browser

Opéra mini

Historic of the view-transition-name property.

  • CSS View Transitions Module Level 1

    This specification module describes view transitions within the same document. View transitions allow an animation to be introduced when part of the page is modified.

    Regarding view-transition-name. First definition of view transitions, and introduction of the view-transition-name property.
    WD
    October 25, 2022
    Working Draft.
    CR
    September 05, 2023
    Candidate Recommendation.
    PR
    REC
  • CSS View Transitions Module Level 2

    This specification module extends the notion of view transition described in level 1 to the transfer from one document to another.

    Regarding view-transition-name. No change to the view-transition-name property.
    WD
    May 16, 2024
    Working Draft.
    CR
    PR
    REC

See also, regarding view transitions.

The specification that defines view transitions is called CSS View Transitions Module.
Many other concepts are also described in this same specification.

Selectors:

::view-transition
Langue française
Pseudo-element targeting elements during the time of a viewtransition.
::view-transition-group()
Langue française
Targets a group of elements created during a view transition.
::view-transition-image-pair()
Langue française
Targets the two screenshots taken for the purposes of a view transition.
::view-transition-new()
Langue française
Targets the screenshot of the new state, in the case of a View Transition.
::view-transition-old()
Langue française
Targets the screenshot of the previous state, in the case of a view transition.
:active-view-transition
Langue française
Targets the root of the document, during a view transition.
:active-view-transition-type()
Langue française
Targets the root of the document, during a view transition of a certain type.

Properties:

View-transition-name
Associates a transition identifier with the targeted element.

At-rules:

@view-transition
Enables or disables display transitions between pages. These transitions allow effects such as fades, slides, etc.