# document.startViewTransition()

> The `document.startViewTransition()` JS method starts an animated transition between two states of the page.

## How do I use the View Transitions API in JavaScript?

The method that takes a callback which updates the DOM and animates the change between the old and new states. Returns a `ViewTransition` object with promises for tracking the progress of the animation.

- Topic: Object on Page
- Type: method
- Browser support: Chrome 111+, Chrome Android 111+, Edge 111+, Firefox 144+, Firefox Android 144+, Safari 18+, Safari iOS 18+

## Example

Wrong:

```js
document.startViewTransition(() => {
  list.innerHTML = renderItems(items);
});
```

Right:

```js
if (!document.startViewTransition) {
  list.innerHTML = renderItems(items);
} else {
  document.startViewTransition(() => {
    list.innerHTML = renderItems(items);
  });
}
```

Feature-detect `startViewTransition()` so browsers without it still update the DOM, just without the animation.

## Common mistakes

- Updating the DOM before calling `startViewTransition()`, so there is nothing to animate.

## Key points

- The code checks for `document.startViewTransition` and runs the DOM update directly when it is missing.
- Animations are reduced or turned off under `prefers-reduced-motion`.
- The DOM is updated inside the callback, and async updates return a promise from it.

## Interview questions

### Does startViewTransition() work across page navigations?

No, `document.startViewTransition()` handles same-document updates. Cross-document transitions are turned on in CSS with the `@view-transition` at-rule.

### How do I customize the view transition animation?

Style the `::view-transition-old()` and `::view-transition-new()` pseudo-elements in CSS, and give elements a `view-transition-name` to animate them separately.

### Can I wait for a view transition to finish?

Yes, the returned `ViewTransition` object has `ready`, `updateCallbackDone` and `finished` promises you can await.

## Related cards

- [view-transition-name](https://wonderium.dev/css/view-transition-name.md)
- [::view-transition](https://wonderium.dev/css/view-transition.md)
- [navigation](https://wonderium.dev/js/navigation.md)
- [@media](https://wonderium.dev/css/media.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/start-view-transition
- Last updated: 2026-11-25
