--- title: Switch description: "`Switch` is a component used to toggle between on and off states." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/switch/switch.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/switch - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-switch--basic --- ```tsx Basic ``` ## Usage ```tsx import { Switch } from "@yamada-ui/react" ``` ```tsx import { Switch } from "@/components/ui" ``` ```tsx import { Switch } from "@workspaces/ui" ``` ```tsx ``` ### Change Variant ```tsx {(variant) => ( {toTitleCase(variant)} )} ``` ### Change Size ```tsx {(size) => ( Size ({size}) )} ``` ### Change Color Scheme ```tsx {(colorScheme) => ( {toTitleCase(colorScheme)} )} ``` ### Change Label Position ```tsx Reverse Label ``` ### Change Shape ```tsx {(shape) => ( {toTitleCase(shape)} )} ``` ### Disable ```tsx Disabled Disabled ``` ### Read-Only ```tsx Read Only Read Only ``` ### Customize Icon ```tsx , on: }} > Dark Mode ``` ### Customize Label ```tsx const id = useId() return ( Please Click ) ``` ### Control ```tsx const [checked, { toggle }] = useBoolean(false) return ( Custom Control ) ``` ## Props | Prop | Default | Type | Description | | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"lg" \| "md" \| "sm"` | The size of the component. | | `variant` | `"thick"` | `"thick" \| "thin"` | The variant of the component. | | `checked` | `false` | `boolean` | If `true`, the switch will be checked. | | `checkOnEnter` | `true` | `boolean` | If `true`, the switch will be checked when the Enter key is pressed. | | `defaultChecked` | `false` | `boolean` | If `true`, the switch will be initially checked. | | `disabled` | `false` | `boolean` | If `true`, the field will be disabled. | | `icon` | - | `ReactNode \| { off: ReactNode; on: ReactNode }` | The switch icon to use. | | `id` | - | `string` | id assigned to input. | | `inputProps` | - | `HTMLStyledProps<"input">` | Props for switch input element. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `labelProps` | - | `HTMLStyledProps<"span">` | Props for switch label element. | | `name` | - | `string` | The HTML `name` attribute used for forms. | | `onBlur` | - | `FocusEventHandler` | The callback invoked when the switch is blurred. | | `onChange` | - | `ChangeEventHandler` | The callback invoked when the checked state changes. | | `onFocus` | - | `FocusEventHandler` | The callback invoked when the switch is focused. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `reverse` | `false` | `boolean` | Change switch label from right to left. | | `shape` | `circle` | `"circle" \| "rounded" \| "square"` | The shape of the switch. | | `tabIndex` | - | `number` | The tab-index property of the underlying input element. | | `value` | - | `Y` | The value to be used in the switch input. | ## Accessibility Currently, this section is being updated due to the migration of v2.