Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

Checkbox

Checkbox is an extension to standard checkbox element with theming.

preview

Usage#

import { Checkbox } from '@primereact/ui/checkbox';
<Checkbox.Root>
    <Checkbox.Box>
        <Checkbox.Indicator />
    </Checkbox.Box>
</Checkbox.Root>

Examples#

Basic#

Toggles a boolean value with an associated label.

basic-demo

Indicator#

Use Checkbox.Indicator to render the visual state inside Checkbox.Box.

indicator-demo

Checkbox.Indicator also accepts a match prop to render based on the checkbox state.

<Checkbox.Root indeterminate>
    <Checkbox.Box>
        <Checkbox.Indicator match="checked">
            <Check />
        </Checkbox.Indicator>
        <Checkbox.Indicator match="unchecked">
            <Times />
        </Checkbox.Indicator>
        <Checkbox.Indicator match="indeterminate">
            <Minus />
        </Checkbox.Indicator>
    </Checkbox.Box>
</Checkbox.Root>

Available match values: checked, unchecked, indeterminate. Without the match prop, the indicator renders in all states.

Indeterminate#

Use the indeterminate property to display an indeterminate state.

indeterminate-demo

Sizes#

Use the size property to change the size of a checkbox.

sizes-demo

Filled#

Specify the variant="filled" property to display the component with a higher visual emphasis than the default outlined style.

filled-demo

Disabled#

Use the disabled property to disable a checkbox.

disabled-demo

Invalid#

Specify the invalid property to display the component with a red border.

invalid-demo

API#

Sub-Components#

See Primitive API for CheckboxRoot, CheckboxBox, CheckboxIndicator, and CheckboxGroup component documentation.

Hooks#

See Headless API for useCheckbox and useCheckboxGroup hook documentation.

Accessibility#

See Checkbox Primitive for WAI-ARIA compliance details and keyboard support.