Edit Profile

Dark Mode

Copy config

Copy and paste the following code into your global.css file to apply the styles.

Checkbox (Two-State)

Allows users to visually select an option by checking it.

Anatomy

ComponentDescription
Checkbox.Root

Defines the component boundary and exposes its internal logic AND must wrap over all other parts

Checkbox.Indicator

Wrapper that automatically shows its children when true and hides them when false

Examples

Controlled Checkbox

To add reactive state, use the bind:checked prop on the <Checkbox.Root /> component.

In the example below, the left checkbox starts as false, while the right checkbox starts as true.

The initial value was: false

The current value is: false

The initial value was: true

The current value is: true

  • item 0
  • item 1

Customization & Caveats

You can apply CSS classes to any part of the component. Any valid HTML can be used as an icon, but children of the Checkbox Indicator are removed from the accessibility tree to prevent them from being added to the Checkbox Label.

Automatic Labeling

The Checkbox element is a div with the role of checkbox, so any text inside the Checkbox Root is interpreted as the checkbox label.

Text tags lose their semantic meaning. For example, an h1 tag is treated the same as a p tag. See this MDN section for more details.

API

Checkbox.Root

ComponentDescription
bind:checked

Two-way data binding of the checkbox value to a user-defined signal

checklist

When true, treats the checkbox as a tri-state and binds its value to all other checkboxes in the checklist