Skip to content

Theme transition

Switches light and dark with a rising view transition; reduced motion swaps at once.

Wrap the call that changes the theme: runThemeTransition(() => setTheme("dark")), with setTheme from next-themes or your own function that sets the dark class on <html>. The next appearance rises over the page from the bottom edge, timed by foundation. A second press part-way jumps to the end and starts again. Where the browser has no View Transitions, and for readers who ask for reduced motion, the theme changes at once. The example changes this site's theme and puts your setting back on the second press, or when you leave the page.

Trying the other theme

Installation

npx shadcn@latest add @khaeli/theme-transition

Pair with next-themes: runThemeTransition(() => setTheme(next)). The keyframes live in @khaeli/foundation.

Installs with

Registry items

Keyboard

EnterSpace
Changes the theme. Focus stays on the button through the transition.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/theme-transition.json