Skip to content

Switch

A control that allows the user to toggle between on and off.

Install

Bash
npx @madeui/cli add switch

Usage

TSX
import { Switch } from '@/components/ui/switch';

<Switch defaultChecked />

Sizes

Description

Pair Switch with Field, FieldContent, and FieldDescription for a labeled setting row.

Receive emails about new products and features.

Disabled

Invalid

Set invalid on Field to show validation errors — the label and error message pick up the invalid styling, and aria-invalid is applied to the switch automatically.

API reference

Built on Base UI Switch. The tables below cover the props this library adds or changes — every other prop is forwarded to the underlying Base UI part; see the Base UI Switch API reference for the full list.

Switch

PropTypeDefaultDescription
size'sm' | 'md''md'
checkedboolean—Controlled checked state.
defaultCheckedbooleanfalse
onCheckedChange(checked: boolean) => void—
disabledbooleanfalse
styleStyleXStyles—StyleX styles merged last — always win over the component’s own styles.

Was this page helpful?