Skip to main content

Switch

Switch is a toggle switch component with size variants, sliding animation, and optional inline labels. Use it for on/off settings.

Open in Storybook

Import

import { Switch } from "@tosui/react";

Basic Usage

Without Label

Sizes

States

Controlled

Use isChecked and onChange for controlled mode.

function ControlledSwitch() {
const [enabled, setEnabled] = useState(false);

return (
<Switch
label={enabled ? "Enabled" : "Disabled"}
isChecked={enabled}
onChange={(e) => setEnabled(e.target.checked)}
/>
);
}

Settings List

Email notifications
Receive email updates
Push notifications
Receive push updates
Marketing emails
Receive marketing content

Props Reference

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"Switch size
labelstring-Optional label text
disabledbooleanfalseDisable the switch
isCheckedboolean-Controlled checked state
defaultCheckedboolean-Initial checked state (uncontrolled)
onChange(e: ChangeEvent) => void-Change handler

Switch also accepts all native <input type="checkbox"> attributes.

Accessibility

  • Uses native <input type="checkbox"> with role="switch"
  • Label is associated with the input
  • Supports keyboard navigation (Space to toggle)
  • When no label is provided, use aria-label for accessibility

TypeScript

import { Switch, type SwitchSize, type SwitchProps } from "@tosui/react";