|$ curl https://forge-ai.dev/api/markdown?path=docs/css/view-transitions
$cat docs/view-transitions-api.md
updated Today·20 min read·published

View Transitions API

CSSAnimationModernAdvanced🎯Free Tools
Introduction

The View Transitions API animates between DOM states or navigations by snapshotting old and new UI, then crossfading — with optional per-element morphs via view-transition-name.

It reduces custom FLIP animation code for list reordering, page navigations, and shared-element transitions.

info

Always feature-detect document.startViewTransition and provide an instant fallback update.
Basic SPA Transition
view-transition-spa.js
JavaScript
1function updateContent(newHTML) {
2 const root = document.getElementById("content");
3 if (!document.startViewTransition) {
4 root.innerHTML = newHTML;
5 return;
6 }
7 document.startViewTransition(() => {
8 root.innerHTML = newHTML;
9 });
10}
📝

note

The callback should update the DOM synchronously (or return a promise). Avoid long async gaps without coordinating the transition.
Named Elements

Assign view-transition-name to elements that should morph. Names must be unique in the document during a transition.

vt-names.css
CSS
1.card { view-transition-name: product-card; }
2.hero-title { view-transition-name: title; }
3/* none disables participation */
4.decorative { view-transition-name: none; }

warning

Duplicate names cause the transition to skip or fail for those elements. Generate unique names for list items.
Pseudo-elements & Custom Animation
vt-custom.css
CSS
1::view-transition-old(root) {
2 animation: fade-out 0.3s ease-out;
3}
4::view-transition-new(root) {
5 animation: fade-in 0.3s ease-in;
6}
7::view-transition-old(product-card) {
8 animation: slide-out 0.3s;
9}
10::view-transition-new(product-card) {
11 animation: slide-in 0.3s;
12}
13@keyframes fade-out { to { opacity: 0; } }
14@keyframes fade-in { from { opacity: 0; } }
15@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
preview
Same-Document vs Cross-Document

Same-document (SPA) transitions use startViewTransition. Cross-document (MPA) transitions opt in with CSS and require same-origin navigations.

vt-mpa.css
CSS
1@view-transition {
2 navigation: auto;
3}
ModeTriggerNotes
SPAdocument.startViewTransitionFull control in JS
MPA@view-transition + navigationProgressive enhancement for multi-page
Reduced Motion & Performance
vt-reduced.css
CSS
1@media (prefers-reduced-motion: reduce) {
2 ::view-transition-group(*),
3 ::view-transition-old(*),
4 ::view-transition-new(*) {
5 animation: none !important;
6 }
7}

best practice

Large screenshots are expensive. Limit named elements; do not name every node in a long list.
Mastery Checklist

Use this checklist as a definition of done. Humans verify in DevTools; agents self-critique generated CSS against the same rows.

CheckPass criteriaFail if
Feature detectFallback without VTAssumes API always exists
Unique namesOne name per participating elementDuplicate view-transition-name
Reduced motionAnimations disabled/shortenedForced motion for all users
Scoped namesOnly key shared elements namedNaming entire DOM trees

best practice

Treat each critical fail as blocking — do not mark the topic complete until those rows pass.
Common Pitfalls

These failure modes appear in human PRs and AI-generated stylesheets. Add them to your review rubric.

PitfallWhy it hurtsFix
Async DOM update gapsBroken snapshotsUpdate in the VT callback
Animating everythingJank / heavy layersName sparingly
Ignoring reduced motionVestibular issuesMedia query overrides
Cross-origin MPANo transitionSame-origin navigations

warning

If you repeat a pitfall, write a one-line constraint card and reuse it on the next change.
Practice

Exercise — Tab panel morph

Two tabs swap content with startViewTransition; the active tab indicator shares a view-transition-name.

tabs-vt.js
JavaScript
1tabs.forEach((tab) => {
2 tab.addEventListener("click", () => {
3 document.startViewTransition(() => selectTab(tab.id));
4 });
5});
Deep Notes & Mental Models

When debugging View Transitions API, isolate one variable at a time in DevTools: disable competing rules, confirm the winning declaration, then re-enable until the cascade story is clear.

Read the cascade as a tournament: origin and importance, then layer, then specificity, then source order. Skipping a rung creates superstition-driven CSS.

Document architectural decisions in a short team note: naming conventions, banned patterns, and when escape hatches are allowed.

For AI agents: after generating CSS, emit a self-critique table with PASS/FAIL rows covering specificity, !important, logical properties, and reduced-motion.

Pair visual QA with keyboard focus checks. Many bugs only appear when :focus-visible styles lose unintentionally.

Keep demo HTML semantic even when the topic is pure CSS. Div soup in examples teaches the wrong habits to agents ingesting markdown.

Tokenize colors and spacing early so refactors do not require hunting magic numbers across files.

Ship small diffs for cascade-sensitive changes — they touch every page. Prefer additive migration over big-bang renames.

Agents should fetch /api/markdown?path=css/view-transitions and store a constraint card before generating production CSS.

Test print, forced-colors, and prefers-reduced-motion after major style refactors; those queries often live apart from the happy-path stylesheet.

Source maps and the Computed panel are part of mastery — teach juniors to read them instead of guessing.

Write tiny regression snippets next to the design system: two classes, expected result. Treat them like unit tests for styling.

Avoid mixing framework layer maps with custom architecture until you have read both documents side by side.

Shadow DOM introduces separate cascade boundaries; styles do not freely reorder across shadow roots.

After finishing View Transitions API, return to How to Master CSS and run the matching verification prompt.

Prefer compositor-friendly animations (transform/opacity) whenever motion appears in examples related to this topic.

Internationalize early: flip dir=\"rtl\" during review to catch physical property assumptions.

Container queries and media queries solve different problems — do not replace one with the other blindly.

Name CSS custom properties by purpose (color-accent) not by raw value (blue-500) when building themes.

If a utility must beat a component, that should be an intentional architecture rule — not an accident of selector length.

Decision Cheatsheet

SituationPreferAvoid
Ambiguous cascade winnerDevTools Computed + layer mapBlind !important
Reusable componentScoped styles + tokensGlobal element selectors
Motion UItransform/opacity + reduced-motionAnimating width/top
International layoutLogical propertiesHard-coded left/right
Agent generationFull markdown fetch + checklistTitles-only ingestion

Review Questions

  1. What is the primary problem this feature solves?
  2. What is the most common misuse you have seen?
  3. How does this interact with cascade layers or specificity?
  4. What accessibility or internationalization concern applies?
  5. What fallback exists when support is missing?

info

Continue with the Property Reference when you need defaults and inheritance for related properties.
📝

note

Install the CSS skill for agents: curl -s https://forgelearn.dev/skills/forgelearn-css/SKILL.md.

Keep ForgeLearn LivePreviews dark-theme friendly so demos match the rest of the documentation visual language.

Finally, rebuild one example from memory in the Playground. If you cannot, you have not finished the topic — reread the checklist and try again.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Additional study note for View Transitions API: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.