---
title: Switch
description: A control that allows the user to toggle between checked and not checked.

link:
  doc: https://kobalte.dev/docs/core/components/switch
  api: https://kobalte.dev/docs/core/components/switch#api-reference
---

<ComponentPreview name="switch-demo">

```tsx file=<rootDir>/apps/docs/src/registry/examples/switch-demo.tsx

```

</ComponentPreview>

## Installation

<ComponentInstallation>

<Step>

<StepItem>Copy and paste the following code into your project:</StepItem>

  <ComponentSourceTabs>

    ```tsx title="components/ui/switch" file=<rootDir>/apps/docs/src/registry/ui/switch.tsx

    ```

    ```tsx title="components/ui/switch" file=<rootDir>/apps/unocss-playground/src/registry/ui/switch.tsx

    ```

  </ComponentSourceTabs>

</Step>

</ComponentInstallation>

## Usage

```tsx
import {
  Switch,
  SwitchControl,
  SwitchInput,
  SwitchThumb,
} from "@components/ui/switch"
```

```tsx
<Switch>
  <SwitchInput />
  <SwitchControl>
    <SwitchThumb />
  </SwitchControl>
</Switch>
```
