---
title: "Pull Cord"
description: "A theme switch you pull like a lamp cord: drag the brass bead down and let go, and the rope springs back as the page goes light or dark."
url: https://gelatinui.com/components/pull-cord
markdown_url: https://gelatinui.com/components/pull-cord.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/pull-cord"
version: "2026-11-11"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Pull Cord

> A theme switch you pull like a lamp cord: drag the brass bead down and let go, and the rope springs back as the page goes light or dark.

Page: https://gelatinui.com/components/pull-cord

## When to use it

Best for: A playful light and dark switch that hangs from the top edge of a page, a header, or a card.

- Wire `value` and `onValueChange` to the theme store of the app, for example next-themes `setTheme`.
- Hang it from a top edge with `absolute top-0`, and leave `length + 44px` of room under the edge.
- Give `PullCordHandle` an `aria-label` that names what the switch turns on, for example "Night reading".

## When not to use it

- For a plain theme switch in a settings row, use a [Theme Switch](https://gelatinui.com/components/theme-switch.md).
- For a choice of light, dark, and system, use a [Theme Picker](https://gelatinui.com/components/theme-picker.md).
- For an on and off setting in a form, use a [Switch](https://gelatinui.com/components/switch.md).

## Notes for agents

- The value is `light` or `dark` only: a cord has two positions, so keep `System` in the app settings.
- A release past 44px of stretch switches; a flick switches with 14px of stretch; a short pull only springs back.
- A tap, Enter, or Space plays the same pull and switches once; a press during the pull does nothing.
- The handle is a `switch` that is on when the value is `dark`. Its default name is "Dark mode".
- The root is `length + 44px` tall: a parent with `overflow: hidden` that is shorter cuts the bead.

## Anatomy

```text
PullCord
├─ PullCordGlow (0..n)
├─ PullCordCord (0..n)
└─ PullCordHandle (0..n)
```

## API reference

### PullCord

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `PullCordValue` |  | The theme the cord shows. Controlled: a pull asks for the other value. |
| `defaultValue` | `PullCordValue` | "light" |  |
| `onValueChange` | `function` |  | Called at the moment of the switch, with the new value. |
| `disabled` | `boolean` | false | Stops new pulls. The bead still swings back to rest. |
| `length` | `number` | PULL_CORD.length | The rest length of the rope in px, from the top edge to the bead. Default 96. |
| `driverRef` | `Ref<DragDriver \| null>` |  | Drives a pull from code (`DragDriver`, no item): a staged scene or a test takes the bead, and the rope, the switch, and the spring back work as for a finger. |

### PullCordGlow

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### PullCordCord

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### PullCordHandle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `style` | `CSSProperties` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| PullCord | `pull-cord` | `data-disabled`, `data-pulling` |  | `motion-timing` |
| PullCordGlow | `pull-cord-glow` | `data-disabled`, `data-pulling` |  | `motion-timing` |
| PullCordCord | `pull-cord-cord` | `data-disabled`, `data-pulling` |  | `motion-timing` |
| PullCordHandle | `pull-cord-handle` | `data-disabled`, `data-pulling` |  | `motion-timing` |

## Usage

Wire the value to your theme, and compose the glow, the cord, and the handle at the top edge of the page.

```tsx title="theme-cord.tsx"
import { useTheme } from "next-themes";

import { PullCord, PullCordCord, PullCordGlow, PullCordHandle } from "@/components/pro/effects/pull-cord";

export function ThemeCord() {
  const { resolvedTheme, setTheme } = useTheme();
  return (
    <PullCord
      value={resolvedTheme === "dark" ? "dark" : "light"}
      onValueChange={setTheme}
      className="absolute top-0 right-6"
    >
      <PullCordGlow />
      <PullCordCord />
      <PullCordHandle aria-label="Dark mode" />
    </PullCord>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/pull-cord
```

It adds 22 registry items: 21 files, 3765 lines, and the npm packages `@base-ui/react`, `@xstate/react`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Theme Switch](https://gelatinui.com/components/theme-switch.md)
- [Theme Picker](https://gelatinui.com/components/theme-picker.md)
- [Switch](https://gelatinui.com/components/switch.md)
- [Button](https://gelatinui.com/components/button.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves the focus to the bead. |
| Enter, Space | Plays one pull and switches between light and dark. |

## Accessibility

The bead is a `switch` with a 44px target. It is checked when the value is `dark`.

Enter and Space play the pull, so the keyboard gets the same switch as a drag.

## Motion

| Part | Motion |
| --- | --- |
| Pull | elastic · the rope stretches under the finger with soft limits, 84px down and 10px up |
| Release | elastic · the rope springs back with the release speed and one bounce, where it goes slack |
| Swing | sway · the bead swings to the side and back after a release or a hover |
| Tap or key | indicator · the bead goes down 52px, switches, and springs back |
| Glow | reveal · switching to light flashes the warm glow, then it rests at 55% |
