Under The Hood
frontend htmx HTMX 1.x / 2.x (View Transitions API)

View Transitions Integration: hx-swap="transition:true" Animation Coordination

Last updated
Prerequisites:
Browser View Transitions API (`document.startViewTransition`)
HTMX hx-swap
  • htmx
  • view-transitions
  • animation
  • transition-true
  • css
  • morphing

Read at your depth

The practical view

HTMX natively integrates with the browser's View Transitions API. By adding the `transition:true` modifier to `hx-swap` (e.g. `hx-swap="innerHTML transition:true"`), HTMX wraps the DOM mutation inside `document.startViewTransition()`. You can then customize the animation using standard CSS pseudo-elements like `::view-transition-old(root)` and `::view-transition-new(root)`.

The same idea in other frameworks

react equivalent
`document.startViewTransition(() => flushSync(() => setTab('tab2')))`.

Legacy vs modern

Abrupt Content Snap vs Smooth View Transition Morph

Standard swaps snap instantly; `transition:true` utilizes browser GPU snapshots for seamless animated transitions.

before → after
Abrupt DOM Snap
<div hx-get="/details" hx-swap="innerHTML"> // ❌ Snaps instantly without visual connection
View Transition Coordination
<button hx-get="/details" hx-swap="outerHTML transition:true"> // ✅ NEW: Smooth morphing animation

Interview gotchas

Context

Interviewers test your knowledge of HTMX global configuration flags.

The mechanical answer

Set the global configuration flag in JavaScript: **`htmx.config.globalViewTransitions = true;`**. This automatically wraps every `hx-swap` operation across the entire application in `document.startViewTransition()` whenever supported by the client browser.

Trap

If using `globalViewTransitions = true`, ensure your CSS doesn't accidentally assign duplicate `view-transition-name` properties to multiple elements simultaneously, or the transition will fail.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.