# Switch

> Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.

```jsx
<Switch defaultChecked />
```

## API Reference

This component inherits props from the [Switch primitive](/primitives/docs/components/switch) and supports [common margin props](/themes/docs/overview/layout#margin-props).

| Prop                                                                                                                          | Type                                                 | Default     |
| ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ----------- |
| `size`                                                                                                                        | `Responsive<"1" \| "2" \| "3">`                      | `"2"`       |
| `variant`The visual variant to apply, see [theme overview](/themes/docs/theme/overview#variants) for more details.            | `"classic" \| "surface" \| "soft"`                   | `"surface"` |
| `color`Overrides the accent color inherited from the Theme. See the [color guide](/themes/docs/theme/color) for more details. | `enum`                                               | —           |
| `highContrast`Uses a higher contrast color for the component.                                                                 | `boolean`                                            | —           |
| `radius`Overrides the radius inherited from the theme. See the [radius guide](/themes/docs/theme/radius) for more details.    | `"none" \| "small" \| "medium" \| "large" \| "full"` | —           |

## Examples

### Size

Use the `size` prop to control the size of the switch.

```jsx
<Flex align="center" gap="2">

	<Switch size="1" defaultChecked />

	<Switch size="2" defaultChecked />

	<Switch size="3" defaultChecked />

</Flex>
```

### Variant

Use the `variant` prop to control the visual style of the switch.

```jsx
<Flex gap="2">

	<Flex direction="column" gap="3">

		<Switch variant="surface" />

		<Switch variant="classic" />

		<Switch variant="soft" />

	</Flex>



	<Flex direction="column" gap="3">

		<Switch variant="surface" defaultChecked />

		<Switch variant="classic" defaultChecked />

		<Switch variant="soft" defaultChecked />

	</Flex>

</Flex>
```

### Color

Use the `color` prop to assign a specific [color](/themes/docs/theme/color).

```jsx
<Flex gap="2">

	<Switch color="indigo" defaultChecked />

	<Switch color="cyan" defaultChecked />

	<Switch color="orange" defaultChecked />

	<Switch color="crimson" defaultChecked />

</Flex>
```

### High-contrast

Use the `highContrast` prop to increase color contrast in light mode.

```jsx
<Grid rows="2" gapX="2" gapY="3" display="inline-grid" flow="column">

	<Switch color="indigo" defaultChecked />

	<Switch color="indigo" defaultChecked highContrast />

	<Switch color="cyan" defaultChecked />

	<Switch color="cyan" defaultChecked highContrast />

	<Switch color="orange" defaultChecked />

	<Switch color="orange" defaultChecked highContrast />

	<Switch color="crimson" defaultChecked />

	<Switch color="crimson" defaultChecked highContrast />

	<Switch color="gray" defaultChecked />

	<Switch color="gray" defaultChecked highContrast />

</Grid>
```

### Radius

Use the `radius` prop to assign a specific radius value.

```jsx
<Flex gap="3">

	<Switch radius="none" defaultChecked />

	<Switch radius="small" defaultChecked />

	<Switch radius="full" defaultChecked />

</Flex>
```

### Alignment

Composing `Switch` within `Text` automatically centers it with the first line of text.

```jsx
<Flex direction="column" gap="3">

	<Text as="label" size="2">

		<Flex gap="2">

			<Switch size="1" defaultChecked /> Sync settings

		</Flex>

	</Text>



	<Text as="label" size="3">

		<Flex gap="2">

			<Switch size="2" defaultChecked /> Sync settings

		</Flex>

	</Text>



	<Text as="label" size="4">

		<Flex gap="2">

			<Switch size="3" defaultChecked /> Sync settings

		</Flex>

	</Text>

</Flex>
```

It is automatically well-aligned with multi-line text too.

### Disabled

Use the native `disabled` attribute to create a disabled switch.

```jsx
<Flex direction="column" gap="2">

	<Text as="label" size="2">

		<Flex gap="2">

			<Switch size="1" />

			Off

		</Flex>

	</Text>



	<Text as="label" size="2">

		<Flex gap="2">

			<Switch size="1" defaultChecked />

			On

		</Flex>

	</Text>



	<Text as="label" size="2" color="gray">

		<Flex gap="2">

			<Switch size="1" disabled />

			On

		</Flex>

	</Text>



	<Text as="label" size="2" color="gray">

		<Flex gap="2">

			<Switch size="1" disabled defaultChecked />

			Off

		</Flex>

	</Text>

</Flex>
```
