Reflex Logo

Intro

Gallery

Hosting

Learn

Components

Recipes

API Reference

Onboarding

Library

/

Chakra

/

Forms

/

Checkbox

A checkbox is a common way to toggle boolean value. The checkbox component can be used on its own or in a group.

rx.chakra.checkbox("Check Me!")

Checkboxes can range in size and styles.

rx.chakra.hstack(
    rx.chakra.checkbox(
        "Example", color_scheme="green", size="sm"
    ),
    rx.chakra.checkbox(
        "Example", color_scheme="blue", size="sm"
    ),
    rx.chakra.checkbox(
        "Example", color_scheme="yellow", size="md"
    ),
    rx.chakra.checkbox(
        "Example", color_scheme="orange", size="md"
    ),
    rx.chakra.checkbox(
        "Example", color_scheme="red", size="lg"
    ),
)

Checkboxes can also have different visual states.

rx.chakra.hstack(
    rx.chakra.checkbox(
        "Example",
        color_scheme="green",
        size="lg",
        is_invalid=True,
    ),
    rx.chakra.checkbox(
        "Example",
        color_scheme="green",
        size="lg",
        is_disabled=True,
    ),
)

Checkboxes can be hooked up to a state using the on_change prop.

Unchecked

import reflex as rx


class CheckboxState(rx.State):
    checked: bool = False

    def toggle(self):
        self.checked = not self.checked


def checkbox_state_example():
    return rx.chakra.hstack(
        rx.cond(
            CheckboxState.checked,
            rx.chakra.text("Checked", color="green"),
            rx.chakra.text("Unchecked", color="red"),
        ),
        rx.chakra.checkbox(
            "Example",
            on_change=CheckboxState.set_checked,
        ),
    )

The Checkbox component is used in forms when a user needs to select multiple values from several options.

PropTypeDefault ValueValues
color_scheme
Literal
size
Literal
is_checked
bool
is_disabled
bool
is_focusable
bool
is_indeterminate
bool
is_invalid
bool
is_read_only
bool
is_required
bool
name
str
value
str
Var.create("true", _var_is_string=True)
spacing
str

Event Triggers

TriggerDescription
on_change

Fired when the checkbox is checked or unchecked

Did you find this useful?

HomeGalleryChangelogIntroductionHosting