Introducing PrimeReact v11-alpha 🎉Discover Now

Checkbox

An unstyled, accessible checkbox component with compound composition and group support.

Build fully custom checkbox controls with complete control over layout and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use Checkbox with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with three sub-components: Root, Box, Indicator
  • CheckboxGroup for managing shared value array across multiple checkboxes
  • Indeterminate state for select-all / partial selection patterns

Usage#

import { Checkbox } from 'primereact/checkbox';
import { CheckboxGroup } from 'primereact/checkboxgroup';
<Checkbox.Root>
    <Checkbox.Box>
        <Checkbox.Indicator />
    </Checkbox.Box>
</Checkbox.Root>
 
<CheckboxGroup>
    <Checkbox.Root value="a">
        <Checkbox.Box>
            <Checkbox.Indicator />
        </Checkbox.Box>
    </Checkbox.Root>
    <Checkbox.Root value="b">
        <Checkbox.Box>
            <Checkbox.Indicator />
        </Checkbox.Box>
    </Checkbox.Root>
</CheckboxGroup>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<Checkbox.Root as="label">
    <Checkbox.Box as="span">
        <Checkbox.Indicator as="div" />
    </Checkbox.Box>
</Checkbox.Root>

Default elements: Root=div, Box=div, Indicator=span.

Render Function Children#

Checkbox.Box and Checkbox.Indicator accept a render function as children, providing access to the component instance.

<Checkbox.Box>{(instance) => <span>{instance.checkbox?.state.checked ? '✓' : ''}</span>}</Checkbox.Box>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

CheckboxRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CheckboxRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CheckboxRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCheckboxRootInstance—
The instance to pass to the component.
ptSafeRecord<CheckboxRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CheckboxRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
checkedboolean—
When present, it specifies the input's checked state.
defaultCheckedboolean—
The default value for the input when not controlled by `checked` and `onCheckedChange` .
indeterminatebooleanfalse
When present, it specifies input state as indeterminate.
trueValuestring | number | booleantrue
Value in checked state.
falseValuestring | number | booleanfalse
Value in unchecked state.
tabIndexnumber—
Tab index for keyboard navigation.
valueunknown—
Value of the checkbox.
namestring—
The name of the checkbox.
size"small" | "large" | "normal"—
Defines the size of the checkbox.
variant"outlined" | "filled"—
Specifies the input variant of the component.
disabledbooleanfalse
When present, it specifies that the element should be disabled.
readOnlybooleanfalse
When present, it specifies that an input field is read-only.
requiredbooleanfalse
When present, it specifies that the element is required.
invalidbooleanfalse
When present, it specifies that the component should have invalid state style.
inputIdstring—
Identifier of the underlying input element.
inputStyleCSSProperties—
Inline style of the input field.
inputClassNamestring—
Style class of the input field.
ariaLabelstring—
Establishes a string value that labels the component.
ariaLabelledbystring—
Establishes relationships between the component and label(s) where its value should be one or more element IDs.
onFocus(event: FocusEvent<HTMLInputElement>) => void—
Callback function that is called when the checkbox is focused.
onBlur(event: FocusEvent<HTMLInputElement>) => void—
Callback function that is called when the checkbox loses focus.
onCheckedChange(event: CheckboxRootChangeEvent) => void—
Callback fired when the checkbox's checked state changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"checkbox"
data-part"root"
data-checkedPresent when checked
data-uncheckedPresent when unchecked
data-disabledPresent when disabled
data-invalidPresent when invalid
data-indeterminatePresent when indeterminate

Defines passthrough(pt) options of CheckboxRoot component.

labeltypedescription
rootCheckboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
inputCheckboxRootPassThroughType<InputHTMLAttributes<HTMLInputElement>>Used to pass attributes to the input's DOM element.
boxCheckboxRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the box's DOM element.
indicatorCheckboxRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the indicator's DOM element.

CheckboxBox#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CheckboxBoxInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CheckboxBoxInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCheckboxBoxInstance—
The instance to pass to the component.
ptSafeRecord<CheckboxBoxPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CheckboxBoxInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"checkbox"
data-part"box"
data-checkedPresent when checked
data-uncheckedPresent when unchecked
data-disabledPresent when disabled
data-invalidPresent when invalid
data-indeterminatePresent when indeterminate

Defines passthrough(pt) options of CheckboxBox component.

labeltypedescription
rootCheckboxBoxPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

CheckboxIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CheckboxIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CheckboxIndicatorInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCheckboxIndicatorInstance—
The instance to pass to the component.
ptSafeRecord<CheckboxIndicatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CheckboxIndicatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
match"checked" | "indeterminate" | "unchecked" | "always"—
Determines the visibility of the indicator based on the state of the checkbox. Valid values are: - "checked": Indicator is visible when the checkbox is checked. - "unchecked": Indicator is visible when the checkbox is unchecked. - "indeterminate": Indicator is visible when the checkbox is in an indeterminate state. - "always": Indicator is always visible.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"checkbox"
data-part"indicator"
data-checkedPresent when checked
data-uncheckedPresent when unchecked
data-disabledPresent when disabled
data-invalidPresent when invalid
data-indeterminatePresent when indeterminate

Defines passthrough(pt) options of CheckboxIndicator component.

labeltypedescription
rootCheckboxIndicatorPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

CheckboxGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: CheckboxGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: CheckboxGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceCheckboxGroupInstance—
The instance to pass to the component.
ptSafeRecord<CheckboxGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: CheckboxGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valueunknown[]—
Value of the checkbox group.
defaultValueunknown[]—
The default value of the checkbox group.
namestring—
The name of the checkboxes.
disabledbooleanfalse
When present, it specifies that the checkbox group should be disabled.
invalidbooleanfalse
When present, it specifies that the checkbox group is invalid.
onValueChange(event: CheckboxGroupChangeEvent) => void—
Callback fired when the checkboxgroup's value state changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"checkboxgroup"
data-part"root"

Accessibility#

Screen Reader#

Checkbox.Root renders a hidden native <input type="checkbox"> that is announced as a checkbox by assistive technologies. The input reflects checked state via aria-checked and uses aria-checked="mixed" for indeterminate state. Provide an accessible name with aria-label, aria-labelledby, or an associated <label> element using inputId.

In a CheckboxGroup, each checkbox is announced individually. Associate labels with inputId + <label htmlFor> or provide aria-label / aria-labelledby on each Checkbox.Root.

Keyboard Support#

KeyFunction
tabMoves focus to the next checkbox.
spaceToggles checked or unchecked state.