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 Space to toggle. Use Tab to navigate between controls.
  • Always pair with a visible label or provide an aria-label for screen readers.