---
title: Switch
description: A control for toggling between unchecked and checked.
component: true
links:
doc: https://www.radix-ui.com/docs/primitives/components/switch
api: https://www.radix-ui.com/docs/primitives/components/switch#api-reference
source:
radix: true
shadcn: true
---
## Installation
CLI
Manual
```bash
npx shadcn-ui@latest add switch
```
Install the following dependencies:
```bash
npm install @radix-ui/react-switch
```
Copy and paste the following code into your project.
Update the import paths to match your project setup.
## Usage
```tsx
import { Switch } from '@/components/ui/switch'
```
```tsx
```
### Relative positioning
When using Switch in custom flex layouts (especially with height constraints like `h-full`), you may need to add `relative` positioning to the parent container to ensure proper rendering of focus rings, form validation messages, and overflow.
```tsx
(
)}
/>
```
You don’t need to add `relative` manually when using FormItemLayout as it provides the necessary positioning context automatically.
## Examples
### Form