Theme switcher
Light, dark or the device’s own, as an icon button, a Segmented control or a menu’s radio group. The theme is saved, on the page before it paints, and every switcher stays in step.
Examples
Default
A ThemeToggle in the header flips between light and dark, and the User menu (opens in a new tab) offers the device’s own as well, through UserMenuTheme. Both stay in step.
Icons
The toggle’s icon: library icons that roll, as a Button’s icons do, or a drawn eclipse or dial. Press each to see it.
Crossovers
Every switcher’s crossover. Under reduced motion, or in a browser without view transitions, the theme changes at once. Press each to see it.
Segmented control
System, light and dark side by side, for a settings page. Name it with aria-labelledby.
Icon only
iconOnly drops the labels, for a footer or a toolbar. Each segment keeps its name for a screen reader.
Installation
npx shadcn@latest add https://kinoui.com/r/theme-switcher.json- Files
lib/refs.tslib/reduce-motion.tslib/resize.tslib/swap.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxlib/scroll.tscomponents/kino/separator.tsxlib/popup.tslib/run-progress.tslib/highlight.tslib/menu.tsxcomponents/kino/dropdown-menu.tsxcomponents/kino/preferences.tsxlib/pill.tscomponents/kino/segmented-control.tsxlib/glide.tsxcomponents/kino/tooltip.tsxcomponents/kino/theme-switcher.tsx- Packages
@base-ui/reactclass-variance-authority
New to Kino? Installation covers what your project needs first and the @kino namespace.
API reference
ThemeToggle
ThemeSegmentedControl
ThemeMenuRadioGroup
Data attributes
Accessibility
- The toggle’s name says what a press does, such as “Switch to the dark theme”, and its tooltip shows the same words.
- The Segmented control and the menu group are radio groups: arrows move between system, light and dark, and the picked one is announced.
- The theme is saved and set before the page paints (the Preferences (opens in a new tab) script), so a reload never flashes the other theme.
- Under reduced motion the theme changes at once: no crossover and no icon movement.
- While a crossover runs, the page takes no pointer input for its length; a key press that changes the theme again turns it back from where it is.