View Transitions API

Smooth animated transitions between DOM states with document.startViewTransition(). Works for tab switches, image galleries, theme changes — any DOM update.

1. Theme Toggle with Full-page Cross-fade

Toggle light/dark/auto theme with a smooth whole-page view transition. Auto follows your OS preference via prefers-color-scheme.

2. Tab Switcher with Cross-fade

Home

Welcome to the home panel. Click the tabs above to see a smooth view transition animation between panels — no JavaScript animation library needed.

3. Image Gallery with Scale Transition

Implementation: View Transitions API (key code)
<style>
  /* Define animations for named transition groups */
  ::view-transition-old(tab-panel) {
    animation: slide-out-left 0.3s ease;
  }
  ::view-transition-new(tab-panel) {
    animation: slide-in-right 0.3s ease;
  }
</style>

<script>
  // Tab switch — scope transition to this element only
  button.addEventListener('click', () => {
    tabContent.style.viewTransitionName = 'tab-panel';
    const t = document.startViewTransition(() => {
      tabContent.innerHTML = panels[targetId];
    });
    t.finished.then(() => {
      tabContent.style.viewTransitionName = '';
    });
  });

  // Theme toggle — full-page cross-fade via root group
  themeBtn.addEventListener('click', () => {
    document.startViewTransition(() => {
      document.documentElement.setAttribute('data-bs-theme', next);
    });
  });
</script>