Skip to content

Switch ​

Switch toggles a boolean in a settings row. Sizes share Button/Input’s sm / md / lg enum; the track is shorter than field height.

Demos ​

Basic

Bind checked and listen for change with e.detail.checked. Provide an accessible name with aria-label when there is no visible label.
Notifications

Size

Size enum matches Button and Input: sm, md, and lg. The track stays smaller than the 28 / 34 / 40 field heights.

Disabled

disabled blocks toggling. An off switch stays subdued; an on switch keeps a readable track.

With label

Default slot text is the visible label and the accessible name. Use :round="false" for a squared track (pill is the default).
Email alertsSquared

Playground

Try combinations of props interactively.
Airplane mode

API ​

Switch Props ​

PropTypeDefault
checkedbooleanfalse
size'sm' | 'md' | 'lg''md'
disabledbooleanfalse
roundbooleantrue

round defaults to pill. In raw HTML a boolean attribute cannot express false; use the property or Vue :round="false".

Switch Slots ​

NameDescription
defaultOptional visible label (also used as the accessible name)

Switch Events ​

NameDescription
changeUser toggled the switch; bubbles; composed: true; detail: { checked: boolean }

Native input / change from a checkbox are not used. Bind Vue/Alpine to this CustomEvent only.

CSS Parts ​

PartDescription
trackThe role="switch" control
thumbKnob inside the track
labelDefault-slot wrapper

Accessibility ​

  • Inner control: role="switch" and aria-checked reflecting checked.
  • Space and Enter toggle.
  • Provide an accessible name via the default slot or aria-label.
  • disabled prevents toggling.