Skip to content

    Browse components

    Theme Toggle

    A day/night switch: the sun rolls across, its rays retract as a shadow bites it into a crescent, clouds drift off and stars burst out and twinkle.

    Open
    Customize

    Installation

    npx shadcn@latest add @glint-ui/theme-toggle

    First time using @glint-ui? Add the registry to components.json once, or install by URL: npx shadcn@latest add https://glintui.vercel.app/r/theme-toggle.json

    Usage

    import { ThemeToggle } from "@/components/ui/theme-toggle";
    
    const { resolvedTheme, setTheme } = useTheme();
    
    <ThemeToggle
      checked={resolvedTheme === "dark"}
      onChange={(dark) => setTheme(dark ? "dark" : "light")}
    />

    Props

    PropTypeDefaultDescription
    sizenumber32Track height in px; width is double.
    labelstring"Dark mode"Accessible label of the switch.
    defaultCheckedbooleanfalseStart in dark mode (uncontrolled).
    checkedReactNode—Controlled state, true = dark. Pair with onChange(dark).
    classNamestring—Extra classes for the root element.