---
title: "Switch"
description: "A toggle for an on/off setting, wired to its label and optional error text."
canonical_url: "https://sanity-id-docs.sanity.build/sanity-id/components/switch"
md_url: "https://sanity-id-docs.sanity.build/sanity-id/components/switch.md"
docs_index: "https://sanity-id-docs.sanity.build/sanity-id/llms.txt"
version: "1.15.2"
---

> Part of the Sanity ID reference. The index of every page is at https://sanity-id-docs.sanity.build/sanity-id/llms.txt.

# Switch

A toggle for an on/off setting, wired to its label and optional error text.

```tsx
import { Switch } from "@sanity/sanity-id/components/switch"
```

## Props

| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `string` | yes | — | Unique input ID; connects the input to its label element |
| `error` | `ReactNode` | no | — | Error message displayed below the switch |
| `label` | `ReactNode` | no | — | Label displayed next to the switch |

Also accepts every prop of `Omit<ComponentProps<"input">, "type">`.

## Usage

```tsx
import { Switch } from "@sanity/sanity-id/components/switch"

export default () => {
	return (
		<div className="flex flex-col gap-32 max-w-md">
			<Switch id="switch-example-1" label="Switch with label" />
			<Switch
				id="switch-example-2"
				label="Switch with label (checked)"
				defaultChecked
			/>
			<Switch
				id="switch-example-3"
				label="Switch with long label. Voluptate deserunt pariatur consequat nulla laborum"
			/>
			<Switch
				id="switch-example-4"
				label="Switch with error"
				error="Esse dolor in nostrud elit incididunt voluptate"
			/>
			<Switch
				id="switch-example-5"
				label="Switch with error (checked)"
				error="Esse dolor in nostrud elit incididunt voluptate"
				defaultChecked
			/>
			<Switch
				id="switch-example-6"
				label="Switch with long error"
				error="Et et dolore ut excepteur voluptate incididunt commodo et minim cillum velit do officia. Sint cupidatat pariatur pariatur labore minim."
			/>
		</div>
	)
}
```

