JavaScript Document startViewTransition() Method

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Newly available
Instance method

What You’ll Learn

document.startViewTransition() is an instance method that starts a same-document (SPA), document-scoped view transition and returns a ViewTransition object (see MDN Document: startViewTransition()). Learn the MDN color demo, updateCallback / options.types, CSS ::view-transition-group, how it compares to Element.startViewTransition(), and five try-it labs.

01

Kind

Instance method

02

Scope

Document / SPA

03

Returns

ViewTransition

04

Args

callback | options

05

CSS

::view-transition-*

06

Status

Baseline 2025

Introduction

Single-page apps often swap content with JavaScript. Without help, those updates feel abrupt. The View Transition API lets the browser snapshot the old UI, apply your DOM update, then animate to the new UI.

MDN: document.startViewTransition() starts a same-document, document-scoped transition and returns a ViewTransition you can await or skip. Pair it with CSS such as ::view-transition-group(root) to control timing and style.

💡
Think: “Snapshot → update DOM → animate”

1) Feature-detect document.startViewTransition
2) Call it with a function that changes the DOM
3) Style the transition with ::view-transition-* CSS
4) If unsupported, just run the DOM update (MDN fallback)

Related tutorials: activeViewTransition, Element.startViewTransition(), getAnimations().

Understanding document.startViewTransition()

An instance method on Document (View Transition API).

  • Job — start a same-document, document-scoped view transition (MDN).
  • Returns — a ViewTransition object (MDN).
  • updateCallback — optional DOM update function that returns a Promise (MDN).
  • options — optional object with update and types (MDN).
  • Reject path — if the callback promise rejects, the transition is abandoned (MDN).
  • CSS — style with ::view-transition-group, ::view-transition-old, ::view-transition-new, and friends.
  • Status — Baseline Newly available since October 2025; some parts may vary (MDN).

📝 Syntax

General forms of Document.startViewTransition (MDN):

JavaScript
startViewTransition()
startViewTransition(updateCallback)
startViewTransition(options)

Parameters

  • updateCallback Optional — callback invoked to update the DOM during the SPA view transition process. It returns a Promise. Invoked once the API has taken a snapshot of the current page. When the promise fulfills, the view transition begins in the next frame. If it rejects, the transition is abandoned (MDN).
  • options Optional — object that may include:
    • update — same as updateCallback; defaults to null (MDN).
    • types — array of strings applied as view transition types for selective CSS/JS; defaults to [] (MDN).

Return value

A ViewTransition object instance (MDN).

MDN basic pattern

JavaScript
const changeColor = () => {
  // Fallback for browsers that don't support View Transitions:
  if (!document.startViewTransition) {
    updateColor();
    return;
  }

  // With View Transitions:
  const transition = document.startViewTransition(() => {
    updateColor();
  });
};

⚡ Quick Reference

GoalCode / note
Feature-detectif (!document.startViewTransition) { /* fallback */ }
Start transitiondocument.startViewTransition(() => updateDom())
With typesdocument.startViewTransition({ update, types: ["theme"] })
Await finishawait transition.finished
Skiptransition.skipTransition()
Active laterdocument.activeViewTransition
CSS duration::view-transition-group(root) { animation-duration: 2s; } (MDN)
MDN statusBaseline Newly available (Oct 2025; some parts vary)

🔍 At a Glance

Four facts about document.startViewTransition().

Returns
ViewTransition

MDN

Scope
document

SPA

Args
fn | options

optional

Status
Baseline

2025

📋 Callback outcomes

SituationWhat happensTip
Callback promise fulfillsTransition begins next frame (MDN)Keep updates synchronous when possible
Callback promise rejectsTransition abandoned (MDN)Catch errors inside the updater
API missingNo animationCall the same updater directly (MDN)
types providedSelective CSS/JS via transition types (MDN)Support for types can vary

Examples Gallery

Examples follow MDN Document: startViewTransition(). Always keep a non-animated fallback.

📚 Getting Started

Detect support and run the MDN color transition demo.

Example 1 — Feature-detect with fallback

MDN: if the method is missing, update the DOM immediately.

JavaScript
function applyUpdate(updateFn) {
  if (!document.startViewTransition) {
    updateFn();
    return null;
  }
  return document.startViewTransition(updateFn);
}

console.log("supported:", typeof document.startViewTransition === "function");
Try It Yourself

How It Works

Same updater function for both paths keeps behavior consistent when animation is unavailable.

Example 2 — MDN: animated color change

Snapshot, update CSS custom property, animate with ::view-transition-group.

JavaScript
const colors = ["darkred", "darkslateblue", "darkgreen"];
const colBlock = document.querySelector("section");
let count = 0;

const updateColor = () => {
  colBlock.style = `--bg: ${colors[count]}`;
  count = count !== colors.length - 1 ? ++count : 0;
};

const changeColor = () => {
  if (!document.startViewTransition) {
    updateColor();
    return;
  }
  document.startViewTransition(() => {
    updateColor();
  });
};

document.querySelector("#change-color").addEventListener("click", changeColor);
Try It Yourself

How It Works

MDN pairs this with CSS like ::view-transition-group(root) { animation-duration: 2s; }.

📈 Practical Patterns

Await finished, pass types, and skip a running transition.

Example 3 — Await transition.finished

Run follow-up logic after the animation completes.

JavaScript
async function swapTitle(nextText) {
  const title = document.getElementById("title");
  const update = () => {
    title.textContent = nextText;
  };

  if (!document.startViewTransition) {
    update();
    console.log("updated without transition");
    return;
  }

  const transition = document.startViewTransition(update);
  await transition.finished;
  console.log("transition finished");
}
Try It Yourself

How It Works

ViewTransition.finished settles when the transition ends (successfully or after skip). Useful for analytics or unlocking UI.

Example 4 — Options object with types

MDN: types enable selective CSS or JS for different transition kinds.

JavaScript
function goTheme(update) {
  if (!document.startViewTransition) {
    update();
    return;
  }

  document.startViewTransition({
    update,
    types: ["theme"],
  });
}

// CSS can target :active-view-transition-type(theme) where supported
Try It Yourself

How It Works

MDN notes some parts of the feature may have varying support — always feature-detect and keep a fallback.

Example 5 — Skip an in-flight transition

Jump straight to the end state when the user navigates again quickly.

JavaScript
let current = null;

function navigate(update) {
  if (current) {
    current.skipTransition();
  }
  if (!document.startViewTransition) {
    update();
    current = null;
    return;
  }
  current = document.startViewTransition(update);
  current.finished.finally(() => {
    if (current && current.finished) current = null;
  });
}
Try It Yourself

How It Works

You can also read document.activeViewTransition instead of storing your own reference.

🚀 Common Use Cases

  • SPA route / panel swaps — animate between same-document UI states (MDN).
  • Theme or color changes — MDN color demo with CSS custom properties.
  • Gallery / list updates — soften abrupt content replacement.
  • Typed transitions — different CSS for “forward” vs “back” via types (MDN).
  • Progressive enhancement — same updater with or without the API (MDN).
  • Widget-scoped motion — prefer Element.startViewTransition() when only one region should animate.

🧠 How startViewTransition() Works

1

API snapshots the current page

Then invokes your update callback (MDN).

Snapshot
2

Your callback updates the DOM

Return a Promise; reject abandons the transition (MDN).

Update
3

Transition begins next frame

CSS ::view-transition-* rules drive the animation.

Animate
4

ViewTransition settles

Await finished, or call skipTransition() if needed.

📝 Notes

  • MDN: Baseline Newly available since October 2025; some parts may vary.
  • Not Deprecated, Experimental, or Non-standard on the Document method page.
  • Always feature-detect and keep an instant DOM-update fallback (MDN).
  • Document-scoped transitions differ from element-scoped ones (see Element tutorial).
  • Style with view-transition pseudo-elements; duration often set on ::view-transition-group(root) (MDN).
  • Related: activeViewTransition, Element.startViewTransition(), getAnimations().

Browser Support

Document.startViewTransition() is Baseline Newly available on MDN (since October 2025). Some parts of this feature may have varying levels of support. Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Newly available

Document.startViewTransition()

Same-document SPA view transitions with a ViewTransition return value and CSS ::view-transition-* styling.

Baseline Newly available
Google Chrome 111+
Yes
Microsoft Edge 111+
Yes
Mozilla Firefox 144+
Yes
Apple Safari 18+
Yes
Opera 97+
Yes
Internet Explorer Not supported
No
startViewTransition() Newly available

Bottom line: Feature-detect document.startViewTransition, update the DOM in the callback, style with ::view-transition-*, and keep an instant fallback for older browsers.

Conclusion

document.startViewTransition() is the document-scoped entry point for same-document view transitions: snapshot, update, animate. Feature-detect, style with view-transition CSS, and fall back to plain DOM updates when needed.

Continue with activeViewTransition, Element.startViewTransition(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling (MDN)
  • Reuse one updater for animated and fallback paths
  • Keep callback work focused on DOM updates
  • Style motion with ::view-transition-* CSS
  • Respect reduced-motion preferences in your CSS

❌ Don’t

  • Assume every browser is brand-new Baseline 2025
  • Forget that rejecting the callback abandons the transition (MDN)
  • Use document scope when a small widget should stay isolated
  • Skip a fallback updater
  • Confuse same-document SPA transitions with full cross-document navigations

Key Takeaways

Knowledge Unlocked

Five things to remember about startViewTransition()

Baseline same-document View Transition entry point.

5
Core concepts
📸02

Flow

snapshot→update

MDN
🎨03

CSS

::view-transition

style
🛡04

Fallback

required

MDN
🎯05

Status

Baseline 2025

MDN

❓ Frequently Asked Questions

MDN: Document.startViewTransition() starts a new same-document (SPA), document-scoped view transition and returns a ViewTransition object to represent it.
No. MDN marks Document.startViewTransition() as Baseline Newly available (since October 2025). Some parts of the feature may have varying support. It is not Deprecated, Experimental, or Non-standard on the Document page.
A ViewTransition object instance (MDN).
Optional function invoked to update the DOM during the SPA view transition. It returns a Promise. The callback runs after a snapshot of the current page; when the promise fulfills, the transition begins in the next frame. If it rejects, the transition is abandoned (MDN).
Document.startViewTransition() is document-scoped (whole-page same-document transitions). Element.startViewTransition() scopes the transition to one element’s subtree so the rest of the page can stay interactive (MDN).
Yes. Always feature-detect. If document.startViewTransition is missing, update the DOM immediately without animation (MDN basic usage pattern).
Did you know?

Same-document view transitions became Baseline Newly available when Firefox 144 shipped support in October 2025 — completing the modern Chrome / Safari / Firefox set for document.startViewTransition(updateCallback).

Next: write()

Learn the Deprecated document.write() stream API and why modern DOM methods are safer.

write() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful