# Switch
Toggle between two states, such as on/off.
```tsx
import { Switch } from '@skeletonlabs/skeleton-react';
export default function Default() {
	return (
		
			
				
			
			Label
			
		
	);
}
```
## Checked Color
Use the [Tailwind data attribute syntax](https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes) to target the active state using `data-[state=checked]`
```tsx
import { Switch } from '@skeletonlabs/skeleton-react';
export default function Colors() {
	return (
		
			
				
			
			Label
			
		
	);
}
```
## List
```tsx
import { Switch } from '@skeletonlabs/skeleton-react';
export default function List() {
	return (
		
			{['Option 1', 'Option 2', 'Option 3'].map((label, i) => (
				
					
						{label}
						
							
						
						
					
					{i < 2 && 
}
				
			))}
		
 
	);
}
```
## Icons
```tsx
import { Switch } from '@skeletonlabs/skeleton-react';
import { MoonIcon, SunIcon } from 'lucide-react';
export default function ThumbIcons() {
	return (
		
			
			
				
					
						{(switch_) => (switch_.checked ?  : )}
					
				
			
			Label
		
	);
}
```
## Direction
```tsx
import { Switch } from '@skeletonlabs/skeleton-react';
export default function Dir() {
	return (
		
			
				
			
			Label
			
		
	);
}
```
## API Reference
### SwitchRootProps
| Property         | Default | Type                                                                                                          | Description                                                                                                                    |
| ---------------- | ------- | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| ids?             | -       | Partial\<\{ root: string; hiddenInput: string; control: string; label: string; thumb: string; }> \| undefined | The ids of the elements in the switch. Useful for composition.                                                                 |
| label?           | -       | string \| undefined                                                                                           | Specifies the localized strings that identifies the accessibility elements and their states                                    |
| disabled?        | -       | boolean \| undefined                                                                                          | Whether the switch is disabled.                                                                                                |
| invalid?         | -       | boolean \| undefined                                                                                          | If \`true\`, the switch is marked as invalid.                                                                                  |
| required?        | -       | boolean \| undefined                                                                                          | If \`true\`, the switch input is marked as required,                                                                           |
| readOnly?        | -       | boolean \| undefined                                                                                          | Whether the switch is read-only                                                                                                |
| onCheckedChange? | -       | ((details: CheckedChangeDetails) => void) \| undefined                                                        | Function to call when the switch is clicked.                                                                                   |
| checked?         | -       | boolean \| undefined                                                                                          | The controlled checked state of the switch                                                                                     |
| defaultChecked?  | -       | boolean \| undefined                                                                                          | The initial checked state of the switch when rendered.
Use when you don't need to control the checked state of the switch. |
| name?            | -       | string \| undefined                                                                                           | The name of the input field in a switch
(Useful for form submission).                                                      |
| form?            | -       | string \| undefined                                                                                           | The id of the form that the switch belongs to                                                                                  |
| value?           | "on"    | string \| number \| undefined                                                                                 | The value of switch input. Useful for form submission.                                                                         |
| dir?             | "ltr"   | "ltr" \| "rtl" \| undefined                                                                                   | The document's text/writing direction.                                                                                         |
| getRootNode?     | -       | (() => ShadowRoot \| Node \| Document) \| undefined                                                           | A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.                                     |
| element?         | -       | ((attributes: HTMLAttributes\<"label">) => Element) \| undefined                                              | Render the element yourself                                                                                                    |
### SwitchRootProviderProps
| Property | Default | Type                                                             | Description                 |
| -------- | ------- | ---------------------------------------------------------------- | --------------------------- |
| value    | -       | SwitchApi\                                            | -                           |
| element? | -       | ((attributes: HTMLAttributes\<"label">) => Element) \| undefined | Render the element yourself |
### SwitchRootContextProps
| Property | Default | Type                                           | Description |
| -------- | ------- | ---------------------------------------------- | ----------- |
| children | -       | (switch\_: SwitchApi\) => ReactNode | -           |
### SwitchControlProps
| Property | Default | Type                                                            | Description                 |
| -------- | ------- | --------------------------------------------------------------- | --------------------------- |
| element? | -       | ((attributes: HTMLAttributes\<"span">) => Element) \| undefined | Render the element yourself |
### SwitchThumbProps
| Property | Default | Type                                                            | Description                 |
| -------- | ------- | --------------------------------------------------------------- | --------------------------- |
| element? | -       | ((attributes: HTMLAttributes\<"span">) => Element) \| undefined | Render the element yourself |
### SwitchLabelProps
| Property | Default | Type                                                            | Description                 |
| -------- | ------- | --------------------------------------------------------------- | --------------------------- |
| element? | -       | ((attributes: HTMLAttributes\<"span">) => Element) \| undefined | Render the element yourself |
### SwitchHiddenInputProps
| Property | Default | Type                                                             | Description                 |
| -------- | ------- | ---------------------------------------------------------------- | --------------------------- |
| element? | -       | ((attributes: HTMLAttributes\<"input">) => Element) \| undefined | Render the element yourself |