---
title: "Switch"
description: "Toggle with a spring-driven thumb and press feedback."
category: "Components"
publishedAt: "2026-05-17"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/components/motion/switch"
markdown: "https://beui.dev/components/motion/switch.md"
license: "MIT"
---

# Switch

> Toggle with a spring-driven thumb and press feedback.

## Install

```bash
npx shadcn@latest add @beui/switch
```

## Dependencies

- `clsx`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { useState } from "react";
import { Switch } from "@/components/motion/switch";

export function SwitchPreview() {
  const [on, setOn] = useState(true);
  return (
    <div className="flex flex-col gap-3">
      <Switch sound checked={on} onCheckedChange={setOn} label="Enable notifications" />
      <Switch sound checked={false} onCheckedChange={() => {}} label="Off" />
      <Switch checked disabled onCheckedChange={() => {}} label="Disabled" />
    </div>
  );
}
```

## API Reference

### Switch

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` |  | Yes | Whether the switch is on. |
| `onCheckedChange` | `(checked: boolean) => void` |  | Yes | Called with the new state when the switch is toggled. |
| `disabled` | `boolean` |  | No | Dims the switch and stops it from toggling. |
| `label` | `string` |  | No | Visible text beside the switch, also its accessible name. |
| `ariaLabel` | `string` |  | No | Accessible name when there is no visible `label`. |
| `sound` | `boolean` | `false` | No | Play a rising blip on, a falling one off. Off by default; a `SoundProvider` can mute it app-wide. |
| `className` | `string` |  | No | Classes merged onto the root element. |

## About Switch

Switch is an animated toggle switch for React built with Framer Motion and styled with Tailwind CSS. The thumb travels on a heavy spring between the off and on positions, squishes slightly while a pointer holds it, and gives a small shake when someone presses it while it is disabled. An optional label sits beside the track and toggles it when clicked.

### When to use it

- A settings screen needs on and off controls for preferences such as notifications, dark mode or autoplay.
- A feature flag or permissions panel turns individual options on and off with an immediate effect.
- A pricing card or form needs a compact toggle, such as switching on an add-on or annual billing.

### Accessibility

The switch renders a real button with the switch role and an aria-checked state, so screen readers announce it as on or off, and Space or Enter toggles it. Pass label to render a visible label tied to the button, or ariaLabel when the switch has no visible text. With reduced motion enabled, the thumb moves without its spring, and the press squish and disabled shake are skipped.

### FAQ

**How do I make an animated toggle switch in React?**

Install the component, then render Switch with checked and onCheckedChange. It is controlled only, so keep the boolean in your own state and update it from onCheckedChange.

**How do I add a label to the switch?**

Pass the label prop to show text next to the track that also toggles the switch when clicked. For an icon-only or unlabeled switch, pass ariaLabel instead so screen readers still get a name.

**Can I disable the switch?**

Yes. Set disabled to block toggling and dim the control. A press on a disabled switch plays a short shake instead of changing state, unless reduced motion is on.

## React Native

A React Native version ships in beUI Native. The detail JSON has every file to copy.

```bash
npx expo install react-native-reanimated react-native-worklets
npm install uniwind tailwindcss
```

- Native detail: https://beui.dev/native/r/switch
- GitHub: https://github.com/starc007/beui-native/tree/main/src/components/switch

## Source

- Registry detail: https://beui.dev/r/switch
- Raw source: https://beui.dev/r/switch/raw
- GitHub: https://github.com/starc007/ui-components
