Xzero UI
Pro library

Switch

A tactile toggle for settings that take effect immediately.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/switch
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/switch

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { Switch } from "@/components/xzero/switch/switch";

export function NotificationsToggle() {
  const [enabled, setEnabled] = useState(true);
  return <Switch label="Email notifications" checked={enabled} onCheckedChange={setEnabled} />;
}

API reference

Switch

A Radix switch whose thumb stretches while pressed and travels on a spring.

PropTypeDefaultDescription
labelstring–Visible label inside the switch; also used as aria-label when none is passed.
checkedboolean–Controlled state.
defaultCheckedbooleanfalseInitial state when uncontrolled.
onCheckedChange(checked: boolean) => void–Called on every toggle.
...propsComponentPropsWithoutRef<typeof SwitchPrimitive.Root>–Radix Switch root props, including ref, name, disabled, and aria-label. Pointer and key handlers are chained, not replaced.

Keyboard interactions

KeysAction
Space / EnterToggles the switch. Holding Space stretches the thumb until release.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in toggles

Guidance for AI tools

Switch: A tactile toggle for settings that take effect immediately. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components