A modern, accessible dark/light theme toggle component for React.
npm install react-theme-togglebun add react-theme-toggleyarn add react-theme-toggleimport { useState } from "react";
import { ToggleTheme } from "react-theme-toggle";
export default function App() {
const [theme, setTheme] = useState("light");
return (
<div className={theme === "dark" ? "dark" : "light"}>
<ToggleTheme selectedTheme={theme} onChange={setTheme} />
</div>
);
}| Prop | Type | Description |
|---|---|---|
selectedTheme |
"light" | "dark" |
The currently selected theme. |
onChange |
(theme) => void |
Called with the new theme on toggle. |
id |
string |
Input id. Default "toggle-theme-switch". |
className |
string |
Extra classes for the visual toggle. |
size |
number |
Track width in px. Default 70. |
disabled |
boolean |
Disables the toggle. |
ariaLabel |
string |
Accessible label. Default "Toggle theme". |
bun install
bun run dev # demo site
bun run build:lib # build the npm package (tsup)
bun run lint # ESLint
bun run typecheck # tsc --noEmitSee CONTRIBUTING.md.
main— the 2026 rewrite (this codebase)legacy— the original v1.x version (Rollup + CSS modules)
