--- layout: "@/layouts/ExplainerLayout.astro" demoTitle: "View Transition Example: Basic Cross-Document, Page 1 of 2" demoText: "Example of a basic cross-document view transition." title: "How does it work?" --- This example features an image carousel where each image is its own web page. ### HTML The HTML structure is straight forward: ```html
...
Next
```
For the styling see the source of this page.
### View Transition specific CSS
The only code needed to enable view transitions for this example consists of a single `@view-transition` rule:
```css
@media (prefers-reduced-motion: no-preference) {
@view-transition {
navigation: auto;
}
}
```
It instructs the browser to do a cross-document transition. The @-rule has to be present on the old and the new page and both pages must share the same origin. Wrapping it in a media query respects the users who prefer reduced motion.
In this example, no specific view-transition-name properties are defined. Instead, the example relies on the default view transition name, `root`, which the browser automatically applies to the `` element. This means that the old and new images are those of the viewport before and after the transition.