# Switch
**📖 Live documentation:** https://cds.coinbase.com/components/inputs/Switch/
A control for toggling between on and off.
## Import
```tsx
import { Switch } from '@coinbase/cds-web/controls/Switch'
```
## Examples
```jsx live
function SwitchDemo() {
const [checked, setChecked] = useState(false);
return (
setChecked((s) => !s)} checked={checked}>
Dark Mode
);
}
```
### Customizing Colors
Like other control components (i.e. Radio, Checkbox), you can customize the color of the Switch by setting the `controlColor` prop.
```jsx live
function SwitchDemo() {
const [checked, setChecked] = useState(false);
return (
setChecked((s) => !s)} checked={checked}>
Custom control color
);
}
```
For more advanced color customization, you can use additional style props like `background`, `borderColor`, `borderWidth`, and `color`:
```jsx live
function AdvancedSwitchDemo() {
const [checked, setChecked] = useState(false);
return (
setChecked((s) => !s)}
>
Advanced styling
);
}
```
### Elevation
You can add a drop shadow to the Switch thumb using the `elevation` prop. By default, the Switch has no elevation.
```jsx live
function ElevationSwitchDemo() {
const [checked, setChecked] = useState(false);
return (
setChecked((s) => !s)} checked={checked}>
With drop shadow
);
}
```
## Props
| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `accessibilityLabel` | `string` | No | `-` | Accessibility label describing the element. |
| `background` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `-` | Background color of the overlay (element being interacted with). |
| `borderColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent \| ResponsiveValue` | No | `-` | - |
| `borderRadius` | `0 \| 100 \| 200 \| 300 \| 400 \| 500 \| 600 \| 700 \| 800 \| 900 \| 1000 \| ResponsiveValue` | No | `-` | - |
| `borderWidth` | `0 \| 100 \| 200 \| 300 \| 400 \| 500 \| ResponsiveValue` | No | `-` | - |
| `children` | `null \| string \| number \| bigint \| false \| true \| ReactElement> \| Iterable \| ReactPortal \| Promise` | No | `-` | Label for the control option. Label content rendered next to the switch control. |
| `className` | `string` | No | `-` | Apply class names to the outer container. |
| `classNames` | `{ readonly root?: string; readonly control?: string \| undefined; readonly track?: string \| undefined; readonly thumb?: string \| undefined; } \| undefined` | No | `-` | - |
| `color` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent \| ResponsiveValue` | No | `-` | - |
| `controlColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `bgPrimary` | Sets the checked/active color of the control. |
| `elevation` | `0 \| 1 \| 2 \| ResponsiveValue` | No | `-` | - |
| `font` | `display1 \| display2 \| display3 \| title1 \| title2 \| title3 \| title4 \| headline \| body \| label1 \| label2 \| caption \| legal` | No | `-` | Typography font token for text. |
| `fontFamily` | `display1 \| display2 \| display3 \| title1 \| title2 \| title3 \| title4 \| headline \| body \| label1 \| label2 \| caption \| legal` | No | `-` | Font family token for text. |
| `fontSize` | `display1 \| display2 \| display3 \| title1 \| title2 \| title3 \| title4 \| headline \| body \| label1 \| label2 \| caption \| legal` | No | `-` | Font size token for text. |
| `fontWeight` | `display1 \| display2 \| display3 \| title1 \| title2 \| title3 \| title4 \| headline \| body \| label1 \| label2 \| caption \| legal` | No | `-` | Font weight token for text. |
| `iconStyle` | `CSSProperties` | No | `-` | Style for the icon element |
| `indeterminate` | `boolean` | No | `-` | Enable indeterminate state. Useful when you want to indicate that sub-items of a control are partially filled. |
| `key` | `Key \| null` | No | `-` | - |
| `labelStyle` | `CSSProperties` | No | `-` | Style for the label element |
| `lineHeight` | `display1 \| display2 \| display3 \| title1 \| title2 \| title3 \| title4 \| headline \| body \| label1 \| label2 \| caption \| legal` | No | `-` | Line height token for text. |
| `onChange` | `FormEventHandler` | No | `-` | - |
| `ref` | `null \| RefObject \| (instance: HTMLButtonElement \| null) => void \| (() => VoidOrUndefinedOnly)` | No | `-` | Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref). |
| `style` | `CSSProperties` | No | `-` | - |
| `styles` | `{ readonly root?: CSSProperties; readonly control?: CSSProperties \| undefined; readonly track?: CSSProperties \| undefined; readonly thumb?: CSSProperties \| undefined; } \| undefined` | No | `-` | - |
| `testID` | `string` | No | `-` | Used to locate this element in unit and end-to-end tests. Under the hood, testID translates to data-testid on Web. On Mobile, testID stays the same - testID |
| `textTransform` | `none \| capitalize \| uppercase \| lowercase` | No | `-` | Text transform for text. |
| `type` | `button \| reset \| submit` | No | `-` | - |
| `value` | `string` | No | `-` | Value of the option. Useful for multiple choice. |
| `variant` | `primary \| positive \| negative` | No | `primary` | Semantic color variant applied to the track when checked. The background prop always takes priority over the background set by the variant, as does any custom style/styles.track. |
## Styles
| Selector | Static class name | Description |
| --- | --- | --- |
| `root` | `cds-Switch` | Persistent outer wrapper across all variants. |
| `control` | `cds-Switch-control` | Underlying Control wrapper element. |
| `track` | `cds-Switch-track` | Track wrapper element. |
| `thumb` | `cds-Switch-thumb` | Thumb wrapper element. |