base-ui-svelte

Checkbox

A control that allows the user to toggle between checked and not checked.

View as Markdown

API Reference

Props mirror Base UI React where applicable, adapted for Svelte 5. Native HTML attributes for the rendered element are also accepted unless noted.

Checkbox.Root

Represents the checkbox itself. Renders a <span> element and a hidden <input> beside.

Props

checked boolean undefined
Name
checked
Description

Controlled checked state.

Type
boolean | undefined
Default
undefined
defaultChecked boolean false
Description

Uncontrolled initial checked state.

Type
boolean
Default
false
onCheckedChange function —
Description

Event handler called when the checked state changes.

Type
((checked: boolean, event: Event) => void) | undefined
disabled boolean false
Description

Whether the control ignores user interaction.

Type
boolean
Default
false
required boolean false
Description

Whether the user must tick the checkbox before submitting a form.

Type
boolean
Default
false
readOnly boolean false
Description

Whether the user should be unable to tick or untick the checkbox.

Type
boolean
Default
false
name string undefined
Name
name
Description

Identifies the field when a form is submitted.

Type
string | undefined
Default
undefined
value string —
Name
value
Description

Controlled value.

Type
string | undefined
uncheckedValue string —
Description

Submitted when the checkbox is unchecked (native form pattern).

Type
string | undefined
form string —
Name
form
Description

Form id association for the hidden input.

Type
string | undefined
indeterminate boolean false
Description

Whether the checkbox is in a mixed state: neither ticked, nor unticked.

Type
boolean
Default
false
parent boolean false
Name
parent
Description

When true inside a CheckboxGroup with allValues, this checkbox controls selecting / clearing the whole group (parent checkbox).

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet<[{ checked: boolean; disabled: boolean; indeterminate: boolean }]>

Data attributes

AttributeDescription
data-checkedPresent when the checkbox is checked.
data-disabledPresent when the checkbox is disabled.
data-indeterminatePresent when the checkbox is in an indeterminate state.
data-readonlyPresent when the checkbox is readonly.
data-uncheckedPresent when the checkbox is not checked.

Checkbox.Indicator

Indicates whether the checkbox is ticked. Renders a <span> element.

Props

keepMounted boolean false
Description

Whether to keep the element in the DOM when the checkbox is not checked.

Type
boolean
Default
false
children snippet —
Description

Content rendered inside the part.

Type
Snippet

Data attributes

AttributeDescription
data-checkedPresent when the checkbox is checked.
data-disabledPresent when the checkbox is disabled.
data-indeterminatePresent when the checkbox is in an indeterminate state.
data-uncheckedPresent when the checkbox is not checked.