---
title: "Switch"
description: "Turns a setting on or off at once, with no Save button. It comes in 3 sizes, with invalid, disabled, and read-only states."
url: https://gelatinui.com/components/switch
markdown_url: https://gelatinui.com/components/switch.md
access: free
install: "npx shadcn@latest add @gelatin-ui/switch"
registry_item: https://gelatinui.com/r/switch.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Switch

> Turns a setting on or off at once, with no Save button. It comes in 3 sizes, with invalid, disabled, and read-only states.

Page: https://gelatinui.com/components/switch

## When to use it

Best for: Turn a setting on or off at once, with no Save button.

- Use it for a setting that changes at once, with no Save button.
- Use `sm` in a dense list and `lg` on a settings card made for touch.

## When not to use it

- In a form with a Save button, use a [Checkbox](https://gelatinui.com/components/checkbox.md).

## Notes for agents

- Apply the change in `onCheckedChange` at once: a Switch has no Save step.
- Name it with a `Label` around it, the Switch first, so the whole row toggles it.

## Anatomy

```text
Switch
```

## API reference

### Switch

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `rounded` | `"default" \| "full"` | "full" |  |
| `size` | `"default" \| "lg" \| "sm"` | "default" |  |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Switch.Root`: https://base-ui.com/react/components/switch

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Switch | `switch` | `aria-invalid`, `data-checked`, `data-disabled`, `data-readonly` | `--background`, `--foreground`, `--radius`, `--switch-thumb`, `--switch-track`, `--switch-track-hover` | `hit-area`, `motion-timing` |

## Usage

Use it for a setting that takes effect at once. The value is `checked`. Put the Switch first inside a `Label`, so the full row toggles it.

The sample also uses `label`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/switch @gelatin-ui/label
```

```tsx title="public-profile-switch.tsx"
import { useState } from "react";

import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";

export function PublicProfileSwitch() {
  const [visible, setVisible] = useState(false);
  return (
    <Label>
      <Switch size="lg" name="publicProfile" checked={visible} onCheckedChange={setVisible} />
      Show my profile in search
    </Label>
  );
}
```

## Compose

Build it with:

- [Sidebar](https://gelatinui.com/components/sidebar.md): Moves between the settings sections.
- [Frame](https://gelatinui.com/components/frame.md): Groups the fields of one section, with Save in its footer.
- [Field](https://gelatinui.com/components/field.md): Names each control and shows its help or error text.
- [Select](https://gelatinui.com/components/select.md): Picks one value from a short list.
- [Button](https://gelatinui.com/components/button.md): Saves the section or opens a dialog.
- [Toast](https://gelatinui.com/components/toast.md): Confirms the save.

Rules:

- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Name every control (`label-every-control`): Give every field a visible `Label` (or a `Field`), and every icon button a `Tooltip` or an `aria-label`.
- Labels real apps use (`real-labels`): Write the button and menu labels that real apps use ("Create API key", "Invite members"), with no "…" at the end.
- No layout jump (`no-layout-jump`): When a state change adds, removes, or resizes content, reserve its space or animate its size, so nothing below it jumps.

Patterns: `gelatin://patterns/settings-page`

## Add it

```bash
npx shadcn@latest add @gelatin-ui/switch
```

It adds 3 registry items: 1 files, 929 lines, and the npm packages `@base-ui/react`, `tailwind-merge`, `tailwind-variants`.

## 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

- [Checkbox](https://gelatinui.com/components/checkbox.md): Pick Checkbox for an option in a form that takes effect only when people press Save or Submit.
- [Label](https://gelatinui.com/components/label.md)
- [Toggle](https://gelatinui.com/components/toggle.md): Pick Toggle for an on or off button with an icon or a label in a toolbar, such as bold or pin.

## Keyboard

| Keys | Action |
| --- | --- |
| Space | Turns the switch on or off. |
| Enter | Turns the switch on or off. |

## Accessibility

Switch is a Base UI `Switch.Root`: a `<span>` with `role="switch"` and `aria-checked`, and a hidden native input for the form. It also sets `aria-readonly` and `aria-required`.

Name it with a `Label`. Base UI reads the label of the hidden input and sets `aria-labelledby` on the switch.

The thumb place shows the state, not only the color. The focus ring shows on keyboard focus only. An invalid switch (`aria-invalid`) shows a red ring and outline.

The track is 32 × 18px (`sm` 24 × 14, `lg` 40 × 22). On a coarse pointer, `hit-area` grows the touch target to at least 44 × 44px.

## Motion

| Part | Motion |
| --- | --- |
| On and off | indicator · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · the thumb slides and the fill fades |
| Hover | hover · 150ms · ease-out (0, 0, 0.2, 1) · the track color |
