Skip to contents

Checkbox

An easily stylable checkbox component.

View as Markdown

Usage guidelines

  • Form controls must have an accessible name: It can be created using a <label> element or the Field component. See Labeling a checkbox and the forms guide.

Anatomy

Import the component and assemble its parts:

Anatomy

Examples

Labeling a checkbox

An enclosing <label> is the simplest labeling pattern:

Wrapping a label around a checkbox

Rendering as a native button

By default, <Checkbox.Root> renders a <span> element to support enclosing labels. Prefer rendering the checkbox as a native button when using sibling labels (htmlFor/id).

Sibling label pattern with a native button

Native buttons with wrapping labels are supported by using the render callback to avoid invalid HTML, so the hidden input is placed outside the label:

Render callback

Form integration

Use Field to handle label associations and form integration:

Using Checkbox in a form

API reference

Root

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

namestringundefined
Name
Description

Identifies the field when a form is submitted.

Type
Default
undefined
defaultCheckedbooleanfalse
Description

Whether the checkbox is initially ticked.

To render a controlled checkbox, use the checked prop instead.

Type
Default
false
checkedbooleanundefined
Description

Whether the checkbox is currently ticked.

To render an uncontrolled checkbox, use the defaultChecked prop instead.

Type
Default
undefined
onCheckedChangefunction
Description

Event handler called when the checkbox is ticked or unticked.

Type
indeterminatebooleanfalse
Description

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

Type
Default
false
valuestring
Name
Description

The value of the selected checkbox.

Type
formstring
Name
Description

Identifies the form that owns the hidden input. Useful when the checkbox is rendered outside the form.

Type
nativeButtonbooleanfalse
Description

Whether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.

Type
Default
false
parentbooleanfalse
Name
Description

Whether the checkbox controls a group of child checkboxes.

Must be used in a Checkbox Group.

Type
Default
false
uncheckedValuestring
Description

The value submitted with the form when the checkbox is unchecked. By default, unchecked checkboxes do not submit any value, matching native checkbox behavior.

Type
disabledbooleanfalse
Description

Whether the component should ignore user interaction.

Type
Default
false
readOnlybooleanfalse
Description

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

Type
Default
false
requiredbooleanfalse
Description

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

Type
Default
false
inputRefReact.Ref<HTMLInputElement>
Description

A ref to access the hidden <input> element.

Type
idstring
Name
Description

The id of the input element.

Type
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-checked

Present when the checkbox is checked.

data-unchecked

Present when the checkbox is not checked.

data-disabled

Present when the checkbox is disabled.

data-readonly

Present when the checkbox is readonly.

data-required

Present when the checkbox is required.

data-valid

Present when the checkbox is in valid state (when wrapped in Field.Root).

data-invalid

Present when the checkbox is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the checkbox’s value has changed (when wrapped in Field.Root).

data-touched

Present when the checkbox has been touched (when wrapped in Field.Root).

data-filled

Present when the checkbox is checked (when wrapped in Field.Root).

data-focused

Present when the checkbox is focused (when wrapped in Field.Root).

data-indeterminate

Present when the checkbox is in an indeterminate state.

AttributeDescription
data-checked

Present when the checkbox is checked.

data-unchecked

Present when the checkbox is not checked.

data-disabled

Present when the checkbox is disabled.

data-readonly

Present when the checkbox is readonly.

data-required

Present when the checkbox is required.

data-valid

Present when the checkbox is in valid state (when wrapped in Field.Root).

data-invalid

Present when the checkbox is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the checkbox’s value has changed (when wrapped in Field.Root).

data-touched

Present when the checkbox has been touched (when wrapped in Field.Root).

data-filled

Present when the checkbox is checked (when wrapped in Field.Root).

data-focused

Present when the checkbox is focused (when wrapped in Field.Root).

data-indeterminate

Present when the checkbox is in an indeterminate state.

Checkbox.Root.PropsHide

Re-Export of Root props as CheckboxRootProps

Checkbox.Root.StateHide

Checkbox.Root.ChangeEventReasonHide

Checkbox.Root.ChangeEventDetailsHide

Indicator

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

classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function
Name
Type
keepMountedbooleanfalse
Description

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

Type
Default
false
renderReactElement | function
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-checked

Present when the checkbox is checked.

data-unchecked

Present when the checkbox is not checked.

data-disabled

Present when the checkbox is disabled.

data-readonly

Present when the checkbox is readonly.

data-required

Present when the checkbox is required.

data-valid

Present when the checkbox is in valid state (when wrapped in Field.Root).

data-invalid

Present when the checkbox is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the checkbox’s value has changed (when wrapped in Field.Root).

data-touched

Present when the checkbox has been touched (when wrapped in Field.Root).

data-filled

Present when the checkbox is checked (when wrapped in Field.Root).

data-focused

Present when the checkbox is focused (when wrapped in Field.Root).

data-indeterminate

Present when the checkbox is in an indeterminate state.

data-starting-style

Present when the checkbox indicator is animating in.

data-ending-style

Present when the checkbox indicator is animating out.

AttributeDescription
data-checked

Present when the checkbox is checked.

data-unchecked

Present when the checkbox is not checked.

data-disabled

Present when the checkbox is disabled.

data-readonly

Present when the checkbox is readonly.

data-required

Present when the checkbox is required.

data-valid

Present when the checkbox is in valid state (when wrapped in Field.Root).

data-invalid

Present when the checkbox is in invalid state (when wrapped in Field.Root).

data-dirty

Present when the checkbox’s value has changed (when wrapped in Field.Root).

data-touched

Present when the checkbox has been touched (when wrapped in Field.Root).

data-filled

Present when the checkbox is checked (when wrapped in Field.Root).

data-focused

Present when the checkbox is focused (when wrapped in Field.Root).

data-indeterminate

Present when the checkbox is in an indeterminate state.

data-starting-style

Present when the checkbox indicator is animating in.

data-ending-style

Present when the checkbox indicator is animating out.

Checkbox.Indicator.PropsHide

Re-Export of Indicator props as CheckboxIndicatorProps

Checkbox.Indicator.StateHide