Basic Usage
Checked State
Passvalue=True to render the switch in its on position from the start. Use this to reflect a setting that already defaults to enabled, so the control matches the state of the system the moment it appears.
Sizes
Switches come in two sizes:With Actions
Theon_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
Setdisabled=True to show a switch whose state is fixed and can’t be toggled. This communicates that a setting is locked by something else — a plan tier, a permission, or another toggle — while still letting the user see whether it’s currently on or off.
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 text displayed next to the switch.
Whether the switch is on.
Switch size:
"default", "sm".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.Whether the switch is non-interactive.
Whether a selection is required for form submission.
Action(s) to execute when toggled.
$event is true when on, false when off.Additional Tailwind CSS classes appended to the component’s built-in styles.
Protocol Reference
Switch