Switch

<wa-switch> Stable Since 2.0

Switches toggle a single setting on or off and apply the change immediately, without requiring a form submission.

Switch

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples

Link to This Section

Checked

Link to This Section

Use the checked attribute to activate the switch.

Checked

The checked attribute is the initial value and does not reflect changes, consistent with native checkboxes. To toggle the checked state with JavaScript, use the checked property instead. To target checked switches with CSS, use the :state(checked) selector.

Disabled

Link to This Section

Use the disabled attribute to disable the switch.

Disabled

Sizes

Link to This Section

Use the size attribute to change a switch's size.

Extra Small
Small
Medium
Large
Extra Large

Hint

Link to This Section

Add descriptive hint to a switch with the hint attribute. For hints that contain HTML, use the hint slot instead.

Label

Custom Styles

Link to This Section

Use the available custom properties to change how the switch is styled.

Really big

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/switch/switch.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/switch/switch.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/switch/switch.js';

To import this component for React 18 or below, use the following code:

import WaSwitch from '@awesome.me/webawesome/dist/react/switch/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Methods

Link to This Section

Learn more about methods.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

CSS parts

Link to This Section

Learn more about CSS parts.

Need a hand? Report a bug Ask for help
    No results