2020-07-15 21:30:37 +00:00
# Switch
[component-header:sl-switch]
```html preview
2020-08-24 14:02:45 +00:00
< sl-switch > Switch< / sl-switch >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlSwitch > Switch< / SlSwitch > ;
2021-11-04 22:12:47 +00:00
```
2022-01-11 14:18:20 +00:00
?> This component works with standard `<form>` elements. Please refer to the section on [form controls ](/getting-started/form-controls ) to learn more about form submission and client-side validation.
2020-07-15 21:30:37 +00:00
## Examples
### Checked
Use the `checked` attribute to activate the switch.
```html preview
< sl-switch checked > Checked< / sl-switch >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlSwitch checked > Checked< / SlSwitch > ;
2021-11-04 22:12:47 +00:00
```
2020-07-15 21:30:37 +00:00
### Disabled
Use the `disabled` attribute to disable the switch.
```html preview
< sl-switch disabled > Disabled< / sl-switch >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlSwitch disabled > Disabled< / SlSwitch > ;
2021-11-04 22:12:47 +00:00
```
2022-12-13 14:28:12 +00:00
## Sizes
2020-08-20 13:09:23 +00:00
2022-12-13 14:28:12 +00:00
Use the `size` attribute to change a switch's size.
2020-08-20 13:09:23 +00:00
```html preview
2022-12-13 14:28:12 +00:00
< sl-switch size = "small" > Small< / sl-switch >
< br / >
< sl-switch size = "medium" > Medium< / sl-switch >
< br / >
< sl-switch size = "large" > Large< / sl-switch >
```
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlSwitch size = "small" > Small< / SlSwitch >
< br / >
< SlSwitch size = "medium" > Medium< / SlSwitch >
< br / >
< SlSwitch size = "large" > Large< / SlSwitch >
< />
);
```
### Custom Styles
Use the available custom properties to change how the switch is styled.
```html preview
< sl-switch style = "--width: 80px; --height: 40px; --thumb-size: 36px;" > Really big< / sl-switch >
2020-08-20 13:09:23 +00:00
```
2020-07-15 21:30:37 +00:00
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
2022-03-02 15:10:41 +00:00
< SlSwitch
2021-11-04 22:12:47 +00:00
style={{
'--width': '80px',
'--height': '32px',
'--thumb-size': '26px'
2022-03-02 15:10:41 +00:00
}}
2021-11-04 22:12:47 +00:00
/>
);
```
2020-07-15 21:30:37 +00:00
[component-metadata:sl-switch]