Switch
A toggle control that allows the user to switch between on and off states.
Default
With Label
Add a label alongside the switch for context.
With Label
Checked State
Use the
checked
attribute to set the initial state.
Checked
Interactive Example
Use
phx-click
to handle toggle events.
Interactive
Disabled
Disabled
Use the disabled attribute to prevent interaction.
Disabled
Accessibility
The switch uses
role="switch"
and
aria-checked
for proper screen reader support.
-
Keyboard:
Press
Spaceto toggle. UseTabto navigate between controls. -
Always pair with a visible label or provide an
aria-labelfor screen readers.