Skip to contentKino
Skip to Content

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.

npx shadcn add https://kinoui.com/r/theme-switcher.json
Share on

Examples

Kino

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.

Roll
Eclipse
Dial

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.

Fade
Reveal
Band

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.

Appearance

Saved on this device, for every workspace.
ThemeLight, dark, or the same as your device.

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

PropTypeDefaultDescription
icon'roll''eclipse''dial''roll'How its icon changes: the sun and moon roll, a crescent’s shadow slides across the sun, or a dial turns the moon up from below.
crossover'fade''reveal''band''fade'How the page crosses over to the new theme: a crossfade, a circle that grows from the control, or a band that opens from its row.
tooltipPropsTooltipContentPropsNoneGo to its TooltipContent, such as side.

ThemeSegmentedControl

PropTypeDefaultDescription
iconOnlybooleanfalseIcons alone, each named for a screen reader.
crossover'fade''reveal''band''fade'How the page crosses over to the new theme: a crossfade, a circle that grows from the control, or a band that opens from its row.
aria-labelstring'Theme'Its name, when aria-labelledby doesn’t point at a visible one.

ThemeMenuRadioGroup

PropTypeDefaultDescription
labelReactNode'Theme'The group’s heading, which also names it for a screen reader; null for none, with an aria-label instead.
inlinebooleanfalseOne row: the heading at its start and the three as icons in a Segmented control (opens in a new tab)’s track, the pill sliding to the pick. Left and Right move along them.
crossover'fade''reveal''band''fade'How the page crosses over to the new theme: a crossfade, a circle that grows from the control, or a band that opens from its row.

Data attributes

AttributeOnDescription
data-sloteach parttheme-toggle, theme-segmented-control and theme-menu-radio-group, to style them from outside.

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.