--- title: Switch description: A control that indicates whether a setting is on or off. links: doc: https://base-ui.com/react/components/switch#api-reference --- ## Installation CLI Manual ```bash npx shadcn@latest add @coss/switch ``` Install the following dependencies: ```bash npm install @base-ui/react ``` Copy and paste the following code into your project. Update the import paths to match your project setup. ## Usage ```tsx import { Switch } from "@/components/ui/switch" ``` ```tsx ``` ## API Reference ### Switch Styled wrapper for `Switch.Root` from Base UI with built-in thumb. Size is controlled via the `--thumb-size` CSS variable. ## Examples For accessible labelling and validation, prefer using the `Field` component to wrap checkboxes. See the related example: [Switch field](/ui/docs/components/field#switch-field). ### Disabled ### With Description ### Customizing Size The switch size is controlled by the `--thumb-size` CSS variable. By default, the switch uses responsive sizing with `[--thumb-size:--spacing(5)] sm:[--thumb-size:--spacing(4)]` classes, making it slightly larger on mobile devices (like other interactive elements). You can customize the size by overriding these CSS variable classes on the component. The `--thumb-size` value can be expressed using: - The spacing scale: `--spacing(3)`, `--spacing(4)`, `--spacing(5)`, etc. - Fixed units: `1rem`, `16px`, etc. ### Card Style ### Form Integration