A switch is a control that toggles between two states, on and off.
<Switch />The Switch supports both uncontrolled and controlled checked states via the defaultChecked and checked props.
Use defaultChecked when you want the switch to manage its own internal state after the initial render. This is ideal for simple use cases where you don't need to sync the value with external state.
<Switch defaultChecked />Use checked when you need full control over the switch state from outside the component (e.g., via React state). This is the recommended approach for forms, state synchronization, or complex interactions.
const [enabled, setEnabled] = useState(false)
;<Switch checked={enabled} onCheckedChange={setEnabled} />onCheckedChangecheckeddefaultChecked for simple, self-contained switcheschecked when the switch state needs to be:
Avoid using both props together, as this can lead to conflicting behavior.
The Switch comes with 2 sizes: 18 and 24 (default).
<Switch size={18} /><Switch size={24} />Use the disabled prop to prevent a switch from being interacted with. Disabled switches communicate that an action is currently unavailable.
<Switch disabled />
<Switch checked disabled />