Skip to main content
Switches provide a visual toggle for binary states, offering an alternative to checkboxes.

Basic Usage

Checked State

Sizes

Switches come in two sizes:

With Actions

The on_change parameter runs actions when the switch is toggled. The $event variable is true when switched on, false when off. Here, toggling the switch updates a separate status message:

Disabled State

Reading the Value

Use .rx to get a reactive reference to the switch’s boolean state. The .then() pipe converts true/false into display-friendly strings: Toggle the switch and the input updates to reflect the current state.

API Reference

Switch Parameters

label
str | None
default:"None"
Label text displayed next to the switch.
value
bool
default:"False"
Whether the switch is on.
size
str
default:"default"
Switch size: "default", "sm".
name
str | None
default:"None"
State key for the switch’s checked state. Auto-generated if not provided. Use .rx to reference the switch’s boolean state in other components without specifying the name explicitly.
disabled
bool
default:"False"
Whether the switch is non-interactive.
required
bool
default:"False"
Whether a selection is required for form submission.
on_change
Action | list[Action] | None
default:"None"
Action(s) to execute when toggled. $event is true when on, false when off.
css_class
str | None
default:"None"
Additional Tailwind CSS classes appended to the component’s built-in styles.

Protocol Reference

Switch
{
  "type": "Switch",
  "name?": "string",
  "label?": "string",
  "value?": false,
  "size?": "sm | default",
  "disabled?": false,
  "required?": false,
  "onChange?": "Action | Action[]",
  "cssClass?": "string"
}
For the complete protocol schema, see Switch.