# Switch
**This documentation is fully rendered on the
[Material Web catalog](https://material-web.dev/components/switch/).**
[Switches](https://m3.material.io/components/switch) toggle the state
of an item on or off.
* [Design article](https://m3.material.io/components/switch)
* [API Documentation](#api)
* [Source code](https://github.com/material-components/material-web/tree/main/switch)
## Usage
Switches are similar to checkboxes, and can be unselected or selected.
```html
```
### Icons
Icons can be used to visually emphasize the switch's selected state. Switches
can choose to display both icons or only selected icons.
```html
```
### Label
Associate a label with a switch using the `` element.
```html
Wi-Fi
Bluetooth
```
## Accessibility
Add an
[`aria-label`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label)
attribute to switches without labels or switches whose labels need to be more
descriptive.
```html
All
```
> Note: switches are not automatically labelled by `` elements and always
> need an `aria-label`. See b/294081528.
## Theming
Switches supports [Material theming](../theming/README.md) and can be customized
in terms of color and shape.
### Tokens
Token | Default value
----------------------------------- | ------------------------------------------
`--md-switch-handle-color` | `--md-sys-color-outline`
`--md-switch-handle-shape` | `--md-sys-shape-corner-full`
`--md-switch-track-color` | `--md-sys-color-surface-container-highest`
`--md-switch-track-shape` | `--md-sys-shape-corner-full`
`--md-switch-selected-handle-color` | `--md-sys-color-on-primary`
`--md-switch-selected-track-color` | `--md-sys-color-primary`
* [All tokens](https://github.com/material-components/material-web/blob/main/tokens/_md-comp-switch.scss)
### Example
```html
```
## API
### MdSwitch <md-switch>
#### Properties
| Property | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `selected` | `selected` | `boolean` | `false` | Puts the switch in the selected state and sets the form submission value to the `value` property. |
| `icons` | `icons` | `boolean` | `false` | Shows both the selected and deselected icons. |
| `showOnlySelectedIcon` | `show-only-selected-icon` | `boolean` | `false` | Shows only the selected icon, and not the deselected icon. If `true`, overrides the behavior of the `icons` property. |
| `required` | `required` | `boolean` | `false` | When true, require the switch to be selected when participating in form submission. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#validation |
| `value` | `value` | `string` | `'on'` | The value associated with this switch on form submission. `null` is submitted when `selected` is `false`. |
| `name` | `name` | `string` | `undefined` | The HTML name to use in form submission. |
| `disabled` | `disabled` | `boolean` | `undefined` | Whether or not the element is disabled. |
| `form` | | `HTMLFormElement` | `undefined` | The associated form element with which this element's value will submit. |
| `labels` | | `NodeList` | `undefined` | The labels this element is associated with. |
| `validity` | | `ValidityState` | `undefined` | Returns a ValidityState object that represents the validity states of the element. https://developer.mozilla.org/en-US/docs/Web/API/ValidityState |
| `validationMessage` | | `string` | `undefined` | Returns a validation error message or an empty string if the element is valid. https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/validationMessage |
| `willValidate` | | `boolean` | `undefined` | Returns whether an element will successfully validate based on forms validation rules and constraints. Disabled and readonly elements will not validate. https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate |
#### Methods
| Method | Parameters | Returns | Description |
| --- | --- | --- | --- |
| `formResetCallback` | _None_ | `void` | |
| `formStateRestoreCallback` | `state` | `void` | |
| `checkValidity` | _None_ | `boolean` | Checks the element's constraint validation and returns true if the element is valid or false if not. If invalid, this method will dispatch an `invalid` event. https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/checkValidity |
| `reportValidity` | _None_ | `boolean` | Checks the element's constraint validation and returns true if the element is valid or false if not. If invalid, this method will dispatch a cancelable `invalid` event. If not canceled, a the current `validationMessage` will be reported to the user. https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/reportValidity |
| `setCustomValidity` | `error` | `void` | Sets the element's constraint validation error message. When set to a non-empty string, `validity.customError` will be true and `validationMessage` will display the provided error. Use this method to customize error messages reported. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity |
#### Events
| Event | Type | [Bubbles](https://developer.mozilla.org/en-US/docs/Web/API/Event/bubbles) | [Composed](https://developer.mozilla.org/en-US/docs/Web/API/Event/composed) | Description |
| --- | --- | --- | --- | --- |
| `input` | `InputEvent` | No | No | Fired whenever `selected` changes due to user interaction (bubbles and composed). |
| `change` | `Event` | No | No | Fired whenever `selected` changes due to user interaction (bubbles). |