JavaScript Element startViewTransition() Method

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Experimental
Limited availability
Instance method

What You’ll Learn

Element.startViewTransition() is an instance method that starts an element-scoped view transition on a DOM subtree and returns a ViewTransition object. Learn MDN’s slideshow demo, the updateCallback and options.types parameters, how it differs from document.startViewTransition(), pairing with activeViewTransition, and five try-it labs aligned with MDN.

01

Kind

Instance method

02

Returns

ViewTransition

03

Scope

Element subtree

04

Callback

updateCallback

05

Types

options.types

06

Status

Experimental

Introduction

View transitions animate DOM updates smoothly instead of swapping content instantly. You may already know document.startViewTransition(), which scopes a transition to the entire page. element.startViewTransition() scopes it to one element’s subtree (MDN).

That means only the scoped region becomes non-interactive during the animation; the rest of the page keeps working. You can run multiple element-scoped transitions at once, and clipped overflow content stays clipped (MDN).

💡
Beginner tip

Pass a callback that updates the element’s DOM. The browser snapshots the old state, runs your callback, then animates to the new state. If startViewTransition is missing, call the same update function directly (MDN slideshow pattern).

This page is part of JavaScript Element. Read activeViewTransition to inspect an in-flight transition without storing the return value.

Understanding the startViewTransition() Method

Calling el.startViewTransition(updateCallback) creates a view transition rooted on el. Only DOM changes inside that element’s subtree are animated (MDN).

  • It is an instance method on Element.
  • Returns a ViewTransition object instance (MDN).
  • updateCallback (optional) — updates DOM during the transition; may return a Promise (MDN).
  • options.update — same as updateCallback when using the options object form (MDN).
  • options.types — array of transition type strings for selective CSS/JS styling (MDN).
  • If the callback’s Promise rejects, the transition is abandoned (MDN).
  • Pseudo-elements like ::view-transition-group(root) are placed inside the transition root (MDN).

📝 Syntax

General form of Element.startViewTransition (MDN):

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

Parameters

  • updateCallback (optional) — function that updates the element’s DOM; may return a Promise (MDN).
  • options.update (optional) — same callback when using the options object (MDN).
  • options.types (optional) — array of strings for view transition types; defaults to [] (MDN).

Return value

A ViewTransition object instance (MDN).

Common patterns

JavaScript
const slide = document.querySelector("section");

function updateSlide() {
  slide.textContent = slide.textContent === "Slide 1" ? "Slide 2" : "Slide 1";
  slide.style.backgroundColor =
    slide.textContent === "Slide 1" ? "green" : "orange";
}

function handleClick() {
  if (!slide.startViewTransition) {
    updateSlide();
    return;
  }
  slide.startViewTransition(() => updateSlide());
}

// Options form with types (MDN)
slide.startViewTransition({
  update: () => updateSlide(),
  types: ["slide-change"]
});

⚡ Quick Reference

GoalCode
Basic transitionel.startViewTransition(() => update())
Feature detectif (el.startViewTransition) { ... }
With typesel.startViewTransition({ update, types })
Store transitionconst vt = el.startViewTransition(fn)
Read active VTel.activeViewTransition
CSS duration::view-transition-group(root) { animation-duration: 1s; }

🔍 At a Glance

Four facts to remember about Element.startViewTransition().

Returns
ViewTransition

Object

Scope
element

Subtree

Callback
update

DOM change

Status
experimental

Limited

📋 Element vs document view transitions

element.startViewTransition()document.startViewTransition()No API fallback
ScopeElement subtree (MDN)Entire documentInstant DOM update
Page interactivityOnly scope blocked (MDN)Whole page blockedAlways interactive
Concurrent transitionsMultiple elements (MDN)One document transitionN/A
overflow clippingStays clipped (MDN)May spill over pageN/A
ReturnsViewTransitionViewTransitionN/A
Best forWidgets, slideshows, cardsFull-page SPA navigationsUniversal fallback

Examples Gallery

Examples follow MDN Element.startViewTransition() patterns. Use View Output or Try It Yourself for each case. Feature-detect before use.

📚 Getting Started

MDN slideshow — animate DOM changes on a section element.

Example 1 — MDN Slideshow (MDN)

Toggle slide content and background color with an element-scoped transition.

JavaScript
const slide = document.querySelector("section");
const btn = document.querySelector("button");

function updateSlide() {
  if (slide.textContent === "Slide 1") {
    slide.textContent = "Slide 2";
    slide.style.backgroundColor = "orange";
  } else {
    slide.textContent = "Slide 1";
    slide.style.backgroundColor = "green";
  }
}

function handleClick() {
  if (!slide.startViewTransition) {
    updateSlide();
    return;
  }
  slide.startViewTransition(() => updateSlide());
}

btn.addEventListener("click", handleClick);
Try It Yourself

How It Works

MDN: call slide.startViewTransition(() => updateSlide()) so DOM changes inside the section animate. CSS can style ::view-transition-group(root).

Example 2 — Feature-detect Fallback (MDN)

Run the same update without animation when the API is unsupported.

JavaScript
function runUpdate(el, updateFn) {
  if (typeof el.startViewTransition === "function") {
    return el.startViewTransition(updateFn);
  }
  updateFn();
  return null;
}

runUpdate(card, () => {
  card.classList.toggle("expanded");
});
Try It Yourself

How It Works

MDN’s slideshow checks slide.startViewTransition before calling the API. Always provide a non-animated path for progressive enhancement.

📈 Practical Patterns

Return value, async updates, and transition types.

Example 3 — Store the ViewTransition Return Value

Keep the returned object to await finished or hook lifecycle events.

JavaScript
const panel = document.getElementById("panel");

const transition = panel.startViewTransition(() => {
  panel.hidden = !panel.hidden;
});

transition.finished.then(() => {
  console.log("element transition finished");
});
Try It Yourself

How It Works

MDN returns a ViewTransition instance. Alternatively, read panel.activeViewTransition while the transition runs.

Example 4 — Async updateCallback with Promise (MDN)

Wait for data before the transition animates to the new state.

JavaScript
const widget = document.getElementById("widget");

widget.startViewTransition(async () => {
  const data = await fetch("/api/widget").then(r => r.json());
  widget.textContent = data.title;
  // Transition begins after this promise fulfills (MDN)
});
Try It Yourself

How It Works

MDN: when the callback returns a Promise, the view transition begins in the next frame after it fulfills. A rejected Promise abandons the transition.

Example 5 — options.types for Styled Transitions (MDN)

Pass transition type strings for selective CSS with :active-view-transition-type().

JavaScript
const card = document.getElementById("card");

card.startViewTransition({
  update: () => card.classList.toggle("flipped"),
  types: ["flip", "card-update"]  // MDN: defaults to []
});
Try It Yourself

How It Works

MDN: options.types enables selective CSS or JavaScript logic based on the kind of transition occurring.

🚀 Common Use Cases

  • Image or content slideshows inside a card (MDN demo).
  • Expanding/collapsing panels without freezing the whole page.
  • Tab panels and widget state changes in SPAs.
  • Multiple simultaneous transitions on different components (MDN).
  • Clipped carousel or overflow-hidden galleries (MDN).
  • Progressive enhancement with instant-update fallback (MDN).

🧠 How startViewTransition() Animates DOM Updates

1

Call on element

el.startViewTransition(callback) roots the transition on that element (MDN).

Start
2

Snapshot old state

Browser captures the current subtree, then invokes your callback (MDN).

Snapshot
3

Update DOM in callback

Changes inside the element scope become the “new” state. Promise must fulfill (MDN).

Update
4

Animate and return ViewTransition

Pseudo-elements animate old → new. Returns ViewTransition; activeViewTransition reflects it while running.

📝 Notes

Limited / Experimental Support

Element.startViewTransition() is Experimental and not Baseline on MDN. It belongs to element-scoped View Transitions (CSS View Transitions Module Level 2). Always feature-detect and keep a plain DOM-update fallback. Logos use the shared browser-image-sprite.png sprite from this project.

Experimental · Not Baseline

Element.startViewTransition()

Start element-scoped view transitions — returns a ViewTransition object.

Limited Experimental
Google Chrome Element-scoped VT — check current versions
Limited / Check
Microsoft Edge Follow Chromium View Transition support
Limited / Check
Opera Follow Chromium where available
Limited / Check
Mozilla Firefox May lag or lack element-scoped APIs — detect
Limited
Apple Safari Check current Safari — feature-detect
Limited
Internet Explorer No View Transition API
No
startViewTransition() Limited

Bottom line: Detect typeof el.startViewTransition === "function" before use. Keep instant DOM updates as fallback. Do not require view transitions for core UX.

Conclusion

Element.startViewTransition() animates DOM updates scoped to one element. MDN’s slideshow pattern: feature-detect, call the same update without the API as fallback, and return a ViewTransition you can await or read via activeViewTransition.

Continue with activeViewTransition, scroll(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect el.startViewTransition (MDN)
  • Keep a non-animated DOM update fallback
  • Scope updates inside the element subtree (MDN)
  • Use options.types for styled transition variants
  • Style with ::view-transition-group(root) (MDN)

❌ Don’t

  • Require view transitions for core functionality
  • Update DOM outside the scoped element and expect animation
  • Ignore rejected Promises in async callbacks (MDN)
  • Assume Baseline support — check MDN compatibility
  • Block the whole page when an element scope is enough

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.startViewTransition()

Element-scoped animations for SPA widgets and slideshows.

5
Core concepts
🌐 02

Scope

element

Subtree
⚙️ 03

Callback

update

DOM
📈 04

Fallback

detect

Enhance
🔬 05

Status

experimental

Limited

❓ Frequently Asked Questions

It starts a same-document (SPA) element-scoped view transition on an element's DOM subtree and returns a ViewTransition object (MDN). DOM updates inside the callback animate only within that element's scope.
MDN marks Element.startViewTransition() as Experimental and Limited availability (not Baseline). It is not Deprecated or Non-standard.
A ViewTransition object instance representing the transition (MDN).
Optional function invoked to update the element's DOM during the transition. It may return a Promise; the transition begins when that promise fulfills. If it rejects, the transition is abandoned (MDN).
Document.startViewTransition() is document-scoped and makes the whole page non-interactive during the transition. Element.startViewTransition() scopes the transition to one element's subtree — the rest of the page stays interactive (MDN).
startViewTransition() returns a ViewTransition you can store. element.activeViewTransition reads the currently active transition on that element (or null) without keeping your own reference.
Did you know?

MDN notes that element-scoped view transitions let you run more than one transition at a time on different elements, and only the scoped region becomes non-interactive — unlike document-scoped transitions that freeze the entire page.

Next: toggleAttribute()

Learn how to toggle Boolean attributes like disabled and hidden.

toggleAttribute() →

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.

8 people found this page helpful