Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Switch

A toggle switch alternative to the checkbox.

Basic Example

Here is a basic example of a switch. We use the on_change trigger to toggle the value in the state.

false

Control the value

The checked prop is used to control the state of the switch. The event on_change is called when the state of the switch changes, when the change_checked event handler is called.

The disabled prop when True, prevents the user from interacting with the switch. In our example below, even though the second switch is disabled we are still able to change whether it is checked or not using the checked prop.

Switch in forms

The name of the switch is needed to submit with its owning form as part of a name/value pair. When the required prop is True, it indicates that the user must check the switch before the owning form can be submitted.

The value prop is only used for form submission, use the checked prop to control state of the switch.

Example Form

Results:

{}

API Reference

rx.switch

A toggle switch alternative to the checkbox.

PropType | ValuesDefaultInteractive
as_child
bool
default_checked
bool
checked
bool
disabled
bool
required
bool
name
str
value
str
size
"1" | "2" | ...
variant
"classic" | "surface" | ...
color_scheme
"tomato" | "red" | ...
high_contrast
bool
radius
"none" | "small" | ...

Event Triggers

See the full list of default event triggers
TriggerDescription
on_change Props to rename Fired when the value of the switch changes