---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Color mode toggle

The app's switch between light and dark, as a button or a menu, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `ColorModeToggle`.

## Try it

Press the moon or the sun, the labelled toggle, or pick System, Light or Dark in the menu: the sample app beside them switches, and all three controls stay in step; the sample’s line says while the menu is open.

The controls hold the sample’s mode, not the page’s, and keep nothing in storage; a light sample cannot be drawn inside a dark page.

## When to use

- The app's switch between light and dark, as a button or a menu.
- Also called: dark mode toggle or theme switcher.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Color mode toggle on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-color-mode-toggle.json --yes
```

```text
Add the Goop Color mode toggle to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { ColorModeToggle, ColorModeMenu, useColorMode } from '@/components/ui/goop/color-mode-toggle';

<>
  <ColorModeToggle />
  <ColorModeToggle iconOnly={false} />
  <ColorModeMenu />
</>
```

- Fits: frame (its recipe).
- Also known as: ThemeToggle, ModeToggle, DarkModeToggle, ThemeSwitcher.
- Every light/dark control is this one or ColorModeMenu, never a Switch or an IconButton wired to the class by hand (it would forget the system's setting). In a top bar it stands among the bar's actions; the README's head script opens the page in the kept mode with no flash.
- width: add no class for these.

## API reference

### Options

- `aria-label?: string` — The icon toggle's name, the same in both modes (its pressed state says which): "Dark mode" when left out.
- `iconOnly?: boolean` — The icon alone (the default); `false` writes words beside it: the mode a press shows ("Dark" while light, "Light" while dark), which name the button.
- `words?: ColorModeWords` — The words, each replaceable.
- `value?: 'light' | 'dark'` — The mode, held by the caller (with `onValueChange`); with this and `defaultValue` left out, the page's own.
- `defaultValue?: ColorMode` — The page's starting mode while no choice is kept (the system's when left out); a kept choice beats it.
- `onValueChange?: (value: 'light' | 'dark') => void` — Called with the mode a press asks for; the page's mode changes only when the toggle is left to the page.
- `type?: 'button' | 'submit' | 'reset'`
- `onClick?: (event: MouseEvent) => void`
- `disabled?: boolean`

- Takes every prop of IconButton but aria-pressed and children (its page: icon-button.md)
- State: value (value / defaultValue / onValueChange)
- Types: ColorModeWords = { light?: string; dark?: string; system?: string }

### Parts

- `ColorModeMenu` — The three-way choice; its props: color-mode-toggle--color-mode-menu.md

- useColorMode
- data-slot values (to select a part by): color-mode-menu, color-mode-toggle

### ColorModeMenu

The three-way choice.

```tsx
import { ColorModeMenu } from '@/components/ui/goop/color-mode-toggle';
```

### Options

- aria-label?: string — The trigger's name: "Appearance" when left out.
- words?: ColorModeWords — The rows' words, each replaceable.
- value?: 'system' | 'light' | 'dark' — The choice, held by the caller (with `onValueChange`); with this and `defaultValue` left out, the page's own.
- defaultValue?: ColorModeChoice — The page's starting choice while none is kept (`system` when left out); a kept choice beats it.
- onValueChange?: (value: 'system' | 'light' | 'dark') => void — Called with the row picked; the page's mode changes only when the menu is left to the page.
- open?: boolean — The menu open, held by the caller (with `onOpenChange`).
- defaultOpen?: boolean — Open when it first draws.
- onOpenChange?: (open: boolean) => void — Called as the menu opens and closes.
- container?: HTMLElement | null — Where the menu is portalled; the end of `<body>` when left out.
- Also takes: type?: 'button' | 'submit' | 'reset'; onClick?: (event: MouseEvent) => void; disabled?: boolean; tooltip?: string | false; tooltipKeys?: readonly string[]; loading?: boolean = false; loadingLabel?: string = 'Loading'
- Types: ColorModeWords = { light?: string; dark?: string; system?: string }

## Keyboard

- Enter: switch to the other mode (the menu: open it)
- Space: switch to the other mode (the menu: open it)

## Accessibility

- The part itself answers the keys above.
- hover, active, focus-visible: the browser's own (:hover, :active, :focus-visible): write nothing
- disabled: the prop disabled

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Menu button](/themes/trail/components/menu-button): The button a menu opens from, shown as words, a workspace's tile or an icon.
- [Copy button](/themes/trail/components/copy-button): A button that copies a value such as a link, a key or a command to the clipboard and says it was copied in place.
- [Link](/themes/trail/components/link): A text link to another page or place, in running text or on its own.
- [Toggle group](/themes/trail/components/toggle-group): A row of toggle buttons that act together, one or several pressed, such as a view switch or text formatting.
