docs.rodeo

MDN Web Docs mirror

@view-transition

{{CSSRef}} 

The @view-transition CSS at-rule is used to opt in the current and destination documents to undergo a view transition, in the case of a cross-document navigation.

For a cross-document view transition to work, the current and destination documents of the navigation also need to be on the same origin.

Syntax

@view-transition {
  navigation: auto;
}

Descriptors

Formal syntax

{{csssyntax}} 

Examples

Transitioning page view

The following code snippets show key concepts used in a page transition demo. The demo uses cross-document view-transitions; a half second transition that occurs when navigating between two pages of a site. For the full demo, see the View transitions multi-page app demo.

The @view-transition at-rule is specified in the CSS for both your current and destination documents of a navigation to opt them both in to the view transition:

@view-transition {
  navigation: auto;
}

In addition to the @view-transition at-rule, we use the {{cssxref("@keyframes")}}  at-rule to define two keyframe animations and use the {{cssxref("animation")}}  shorthand property to apply those keyframe animations to the elements in the outbound ({{cssxref("::view-transition-old()")}} ) and inbound ({{cssxref("::view-transition-new()")}} ) pages that we want to animate.

/* Create a custom animation */
@keyframes move-out {
  from {
    transform: translateY(0%);
  }

  to {
    transform: translateY(-100%);
  }
}

@keyframes move-in {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0%);
  }
}

/* Apply the custom animation to the old and new page states */
::view-transition-old(root) {
  animation: 0.4s ease-in both move-out;
}

::view-transition-new(root) {
  animation: 0.4s ease-in both move-in;
}

See this transitions multi-page app demo live.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN