Font Awesome Build Awesome
Search ⌘KCtrl+K
Light Dark System Docs Color Scheme: System \ Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Theme: Default Icon Style: Classic Regular
Solid Regular Light Thin Classic Sharp Duotone Sharp Duotone
Docs Most styles require Font Awesome Pro.
Server-Side Rendering: Off Server-Side Rendering Docs
View on GitHub
Start Components Docs Help
Web Awesome Font Awesome Build Awesome
Search this site… /
Light Dark System Docs Color Scheme: System \ Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Theme: Default Icon Style: Classic Regular
Solid Regular Light Thin Classic Sharp Duotone Sharp Duotone
Docs Most styles require Font Awesome Pro.
Server-Side Rendering: Off Server-Side Rendering Docs
View on GitHub
Components

Getting Started

  • Installation
  • Usage
  • Forms
  • Localization
  • Frameworks
  • Using with AI
  • Figma Design Kit ProThis requires access to Web Awesome Pro
  • Server Rendering

Resources

  • Accessibility
  • Browser Support
  • Contributing
  • Patterns ProPatterns require access to Web Awesome Pro
  • Migrating from Shoelace
  • Visual Tests
  • Changelog
  • Help & Support

Theming & Utilities

  • Overview
  • Built-in Themes
  • Color Palettes
  • Design Tokens
  • Customizing & Theming
  • CSS Utilities

Actions

  • Button
  • Button Group
  • Copy Button
  • Dropdown
    • Dropdown Item

Forms

  • Checkbox
  • Checkbox Group
  • Color Picker
  • Input
  • Known Date
  • Number Input
  • OTP Input
  • Radio Group
    • Radio
  • Rating
  • Select
    • Option
  • Slider
  • Switch
  • Tag Input
  • Textarea
  • Time Input

Layout

  • Accordion
    • Accordion Item
  • Card
  • Details
  • Dialog
  • Divider
  • Drawer
  • Page
  • Scroller
  • Split Panel
  • Timeline
    • Timeline Item

Navigation

  • Breadcrumb
    • Breadcrumb Item
  • Pagination
  • Stepper
    • Step
  • Tab Group
    • Tab
    • Tab Panel
  • Tree
    • Tree Item

Feedback

  • Badge
  • Callout
  • Progress Bar
  • Progress Ring
  • Skeleton
  • Spinner
  • Tag
  • Toast
    • Toast Item
  • Tooltip

Media

  • Animated Image
  • Avatar
  • Carousel
    • Carousel Item
  • Code Highlighter
  • Comparison
  • Icon
  • Lightbox
    • Lightbox Item
  • Markdown
  • QR Code
  • Zoomable Frame

Data Viz

  • Advanced Usage

Helpers

  • Animation
  • Counter
  • Format Bytes
  • Format Date
  • Format Number
  • Include
  • Intersection Observer
  • Mutation Observer
  • Number Ticker
  • Popover
  • Popup
  • Random Content
  • Relative Time
  • Resize Observer

Switch

  • Examples
  • Label
  • Hint
  • Initial Value
  • Disabled
  • Size
  • Custom Properties
  • API
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • CSS Custom Properties
  • Custom States
  • CSS Parts
On This Page...
  • Examples
  • Label
  • Hint
  • Initial Value
  • Disabled
  • Size
  • Custom Properties
  • API
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • CSS Custom Properties
  • Custom States
  • CSS Parts

Switch

<wa-switch>
Stable Forms Since 2.0

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

Enable notifications
<wa-switch>Enable notifications</wa-switch>

This component works with standard <form> elements. See form controls for form submission and client-side validation.

Examples

Link to This Section

Label

Link to This Section

Add label text as the switch's default content. For labels that contain HTML, slot the markup in directly.

Subscribe to the newsletter
<wa-switch>Subscribe to the newsletter</wa-switch>

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.

Email me about new releases
<wa-switch hint="You can change this at any time in settings.">Email me about new releases</wa-switch>

Initial Value

Link to This Section

Use the checked attribute to activate the switch.

Remember this device
<wa-switch checked>Remember this device</wa-switch>

checked sets the initial value, not the current state.
Consistent with native checkboxes, it doesn't reflect later changes. 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.

Sync over cellular
<wa-switch disabled>Sync over cellular</wa-switch>

Size

Link to This Section

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

Extra Small Small Medium Large Extra Large
<div class="wa-stack">
  <wa-switch size="xs">Extra Small</wa-switch>
  <wa-switch size="s">Small</wa-switch>
  <wa-switch size="m">Medium</wa-switch>
  <wa-switch size="l">Large</wa-switch>
  <wa-switch size="xl">Extra Large</wa-switch>
</div>

Custom Properties

Link to This Section

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

Really big
<wa-switch style="--width: 80px; --height: 40px; --thumb-size: 36px;">Really big</wa-switch>

API

Link to This Section

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.

Name Description
(default) The switch's label.
hint Text that describes how to use the switch. Alternatively, you can use the hint attribute.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Name Description Reflects
checked
Draws the checkbox in a checked state.
defaultChecked
checked
The default value of the form control. Primarily used for resetting the form control.
Type boolean
disabled
disabled
Disables the switch.
Type boolean
Default false
form
By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work.
Type HTMLFormElement | null
hint
hint
The switch's hint. If you need to display HTML, use the hint slot instead.
Type string
Default ''
name
name
The name of the switch, submitted as a name/value pair with form data.
Type string | null
Default null
required
required
Makes the switch a required field.
Type boolean
Default false
size
size
The switch's size.
Type 'xs' | 's' | 'm' | 'l' | 'xl'
Default 'm'
value
value
The value of the switch, submitted as a name/value pair with form data.
Type string | null
withHint
with-hint
Only required for SSR. Set to true if you're slotting in a hint element so the server-rendered markup includes the hint before the component hydrates on the client.
Type boolean
Default false

Methods

Link to This Section

Learn more about methods.

Name Description Arguments
blur() Removes focus from the switch.
click() Simulates a click on the switch.
focus() Sets focus on the switch. options: FocusOptions
setCustomValidity() Sets a custom validation message. While the message is set, the form control is invalid and the message is shown when validity is reported. Pass an empty string to clear it. message: string

Events

Link to This Section

Learn more about events.

Name Description
blur Emitted when the control loses focus.
change Emitted when the control's checked state changes.
focus Emitted when the control gains focus.
input Emitted when the control receives input.
wa-invalid Emitted when the form control has been checked for validity and its constraints aren't satisfied.

CSS Custom Properties

Link to This Section

Learn more about CSS custom properties.

Name Description
--height
The height of the switch.
--thumb-size
The size of the thumb.
--width
The width of the switch.

Custom States

Link to This Section

Learn more about custom states.

Name Description CSS selector
disabled Applied when the form control is disabled. :state(disabled)
invalid Applied when the form control fails validation. :state(invalid)
optional Applied when the form control is not required. :state(optional)
required Applied when the form control is required. :state(required)
user-invalid Applied when the form control fails validation after the user has interacted with it. :state(user-invalid)
user-valid Applied when the form control passes validation after the user has interacted with it. :state(user-valid)
valid Applied when the form control passes validation. :state(valid)

CSS Parts

Link to This Section

Learn more about CSS parts.

Name Description CSS selector
control The control that houses the switch's thumb. ::part(control)
hint The hint's wrapper. ::part(hint)
label The switch's label. ::part(label)
switch The component's outer wrapper. ::part(switch)
thumb The switch's thumb. ::part(thumb)
base Deprecated. Use the switch part instead. ::part(base)
Need a hand? Report a bug Ask for help
Go Make Something Awesome
Version 3.15.0 © Fonticons, Inc.
  • Terms
  • Privacy
  • Refunds
  • Core License
  • Pro License

Quick Links

  • Components
  • CSS Utilities
  • Theming
  • Using with AI
  • Changelog
  • Help & Support

Recent Searches

    D'oh! No results for “”

    Suggest on GitHub Ask on Discord
    Navigate Select
    Close Esc