Switch
Toggle Switch
NewAn on/off switch with a label and description, three sizes and a thumb that stretches as you press it.
npx motionsnack add toggle-switchCustomize
<ToggleSwitch />Props
18 properties
| Property | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | Controlled state. Leave undefined to let the component manage it. |
| defaultChecked | boolean | true | State on first render when uncontrolled. |
| onChange | (checked: boolean) => void | - | Called with the new state on every change. |
| aria-label | string | - | Accessible name when there is no visible label (ariaLabel is a deprecated alias). |
| name | string | - | Name submitted with a form. |
| value | string | 'on' | Value submitted with a form while the switch is on. |
| id | string | generated | Id of the input. |
| className | string | '' | Extra classes on the wrapper. |
| label | string | 'Public profile' | Text next to the switch. Empty hides it. |
| description | string | 'Anyone with the link can see your portfolio.' | Second line under the label. Empty hides it. |
| labelPosition | 'right' | 'left' | 'right' | Which side of the switch the text sits on. |
| size | 'sm' | 'md' | 'lg' | 'md' | Size of the switch: S 28x16, M 36x20, L 44x24. |
| showIcons | boolean | false | A tiny check / cross inside the thumb that cross-fade with the state. |
| busy | boolean | false | Waiting for an async change: a spinner in the thumb, presses are ignored. |
| error | string | '' | Error message. Any text draws the track edge in the error colour and shows the message. |
| errorColor | string | '' | Overrides the per-theme error colour. Empty uses the theme pair. |
| required | boolean | false | Marks the switch as required. |
| disabled | boolean | false | Disables the switch. |
About Toggle Switch
Toggle Switch turns a setting on or off with one click. Under the drawn track sits a real checkbox with the switch role, so the keyboard, forms and screen readers work exactly as they should. The thumb slides across on a soft ease and stretches a little toward the middle while it is held, the track fills black or white when it is on, and an optional tiny check and cross inside the thumb cross-fade with the state. A label and a second line of description sit on either side, in small, medium or large, and the switch shares the library's soft focus outline, required mark, disabled look and error state with every other field.
What's included
- Real checkbox with the switch role underneath
- Thumb that slides and stretches while pressed
- Small, medium and large sizes
- Label and description on either side
- Optional check and cross icons in the thumb
- Focus outline, required, disabled and error states
- Light and dark look
- Type
- Animated React switch component
- Library
- Components · Switch
- Stack
- Next.js, React, Tailwind CSS
- Added
- 2026-11-23
- Install
npx motionsnack add toggle-switch