Skip to main content

A checkbox with a checked, unchecked and indeterminate state.

<primitives:checkbox.root>
    <primitives:checkbox.control>
        <primitives:checkbox.indicator />
    </primitives:checkbox.control>
    <primitives:checkbox.label />
    <primitives:checkbox.hiddenInput />
</primitives:checkbox.root>
typo3 ui:add checkbox

Read more about installing Components and Primitives.

Pass defaultChecked="{true}" to render the checkbox checked.

Pass defaultChecked="indeterminate" for a "select all" checkbox while only some of its options are selected.

Pass disabled="{true}" to block interaction with the checkbox.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Groups the checkbox control, label, and input into one interactive label. Renders a <label> element.

NameDescriptionRequiredDefault
disabledboolean
Whether the checkbox is disabled. Inherited from a surrounding field when available.
No
-
invalidboolean
Whether the checkbox is invalid. Inherited from a surrounding field when available.
No
-
requiredboolean
Whether the checkbox is required. Inherited from a surrounding field when available.
No
-
defaultCheckedmixed
The initial checked state of the checkbox when rendered. Use when you don't need to control the checked state of the checkbox.
No
false
namestring
The name of the input field in the checkbox. Useful for form submission. Inherited from a surrounding field when available.
No
-
formstring
The id of the form that the checkbox belongs to.
No
-
readOnlyboolean
Whether the checkbox is read-only. Inherited from a surrounding field when available.
No
-
valuestring
The value of checkbox input. Useful for form submission.
No
1
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-checkbox-root<uid>
data-activePresent when active or pressed
data-focusPresent when focused
data-focus-visiblePresent when focused with keyboard
data-readonlyPresent when read-only
data-hoverPresent when hovered
data-disabledPresent when disabled
data-state"indeterminate" | "checked" | "unchecked"
data-invalidPresent when invalid
data-requiredPresent when required

Provides the native checkbox input for form submission and browser integration. Renders an <input> element, with the empty-value input that submits '' while the box is unchecked in front of it.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Displays the visual checkbox box that reflects the checked state. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-checkbox-control<uid>
data-activePresent when active or pressed
data-focusPresent when focused
data-focus-visiblePresent when focused with keyboard
data-readonlyPresent when read-only
data-hoverPresent when hovered
data-disabledPresent when disabled
data-state"indeterminate" | "checked" | "unchecked"
data-invalidPresent when invalid
data-requiredPresent when required

Displays the checked or indeterminate indicator inside the control. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-checkbox-indicator<uid>
data-activePresent when active or pressed
data-focusPresent when focused
data-focus-visiblePresent when focused with keyboard
data-readonlyPresent when read-only
data-hoverPresent when hovered
data-disabledPresent when disabled
data-state"indeterminate" | "checked" | "unchecked"
data-invalidPresent when invalid
data-requiredPresent when required

Displays the visible label text for the checkbox. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-checkbox-label<uid>
data-activePresent when active or pressed
data-focusPresent when focused
data-focus-visiblePresent when focused with keyboard
data-readonlyPresent when read-only
data-hoverPresent when hovered
data-disabledPresent when disabled
data-state"indeterminate" | "checked" | "unchecked"
data-invalidPresent when invalid
data-requiredPresent when required
NameTypeDescription
checkedbooleanWhether the checkbox is checked
disabledboolean | undefinedWhether the checkbox is disabled
indeterminatebooleanWhether the checkbox is indeterminate
focusedboolean | undefinedWhether the checkbox is focused
checkedStateCheckedStateThe checked state of the checkbox
setChecked(checked: CheckedState) => voidFunction to set the checked state of the checkbox
toggleCheckedVoidFunctionFunction to toggle the checked state of the checkbox
getRootState() => RootStateReturns the state of the checkbox
KeyDescription
SpaceToggle the checkbox