Theme transitions
Animate dark mode and color theme changes with the View Transitions API. Choose the animation, the origin, and the duration.
UI-Theme animates theme changes with the browser's View Transitions API. The same engine animates light and dark mode changes and color theme changes. React, Next.js, TanStack Start, Vue, and Nuxt use the same transition options.
How a transition works
- Your app calls
switchTheme,switchColorTheme, or a toggle function. - UI-Theme calls
document.startViewTransition. The browser captures the current page. - UI-Theme applies the new theme class to the document.
- UI-Theme animates the new page over the old page, then removes its temporary styles.
setTheme and setColorTheme change the theme immediately, with no animation.
Animation types
Set animationType on a call or on a styled control. The default is circle.
animationType | Behavior |
|---|---|
circle | A circle grows from the origin. |
blur-circle | A circle with a soft edge grows from the origin. blurAmount sets the edge. The default is 2. |
slide | The new theme slides in. slideDirection sets the start side. The default is left. |
clip-path | A polygon wipe starts at clipPathDirection. The default is top-left. |
polygon-gradient | A wipe with a soft edge. gradientWidth sets the edge in CSS pixels. The default is 80. |
triangle | A triangle grows from the origin. |
svg-logo | Your SVG logo stays at the center of the viewport while the theme changes. |
The svg-logo type needs logo, or both logoLight and logoDark.
Set the origin
The circle and triangle types start from an origin. UI-Theme chooses the origin in this order:
origin: a fixed point in viewport CSS pixels, such as{ x: 0, y: 0 }.animationPosition:center, or an edge or corner such astop-right.element: the center of the clicked control.
Pass the clicked element to start the animation from the control:
In Vue, pass the click event or the same options object:
A circle or blur-circle call with no origin, position, or element changes the theme without animation.
The svg-logo type always uses the center of the viewport.
Duration and easing
durationsets the length in milliseconds. The default is 400.easingsets the CSS timing function. The default iscubic-bezier(0.32, 0.72, 0, 1).- A
durationof 0 or less turns off the animation for that call. - Pass
animationOff: trueto change the theme without animation once.
Styled controls accept animationType and duration props. Only the slide controls accept slideDirection.
When the theme changes without animation
The theme always changes. UI-Theme skips only the animation when:
- the browser does not support the View Transitions API;
- the user turns on reduced motion (
prefers-reduced-motion: reduce); - the page is hidden;
- a newer theme change starts before the animation is ready. The newer change runs, and the older animation stops.
Color themes
switchColorTheme animates a palette change with the same options.
Palette classes use the theme- prefix by default, such as .theme-caffeine.
The dark appearance and the color theme stay separate.
Follow Tailwind and palette setup to define palette styles.
For a Content Security Policy in React, pass a nonce to the provider. UI-Theme adds the nonce to each <style> element that it injects for a transition.

