Checkbox
Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected.
Installation
The above command is for individual installation only. You may skip this step if @heroui/react is already installed globally.
Import
Usage
Disabled
Sizes
Colors
Radius
Indeterminate
The isIndeterminate prop sets a Checkbox to an indeterminate state, overriding its appearance and maintaining it until set to false, regardless of user interaction.
Line Through
Custom Check Icon
By default,
IconPropswill be passed to your icon component. Please make sure thatisSelected,isIndeterminate, anddisableAnimationare not passed to a DOM element.
Controlled
Note: HeroUI
Checkboxalso supports native events likeonChange, useful for form libraries such as Formik and React Hook Form.
Slots
- base: Checkbox wrapper, it handles alignment, placement, and general appearance.
- wrapper: An inner container that includes styles for relative positioning, flex properties, overflow handling and managing hover and selected states.
- hiddenInput: The hidden input element that is used to handle the checkbox state.
- icon: Icon within the checkbox, controlling size, visibility, and changes when checked.
- label: The text associated with the checkbox.
Custom Styles
You can customize the Checkbox component by passing custom Tailwind CSS classes to the component slots.
Custom Implementation
In case you need to customize the checkbox even further, you can use the useCheckbox hook to create your own implementation.
Note: We used Tailwind Variants to implement the styles above, you can use any other library such as clsx to achieve the same result.
Data Attributes
Checkbox has the following attributes on the base element:
- data-selected:
When the checkbox is checked. Based on
isSelectedprop. - data-pressed: When the checkbox is pressed. Based on usePress
- data-invalid:
When the checkbox is invalid. Based on
validationStateprop. - data-readonly:
When the checkbox is readonly. Based on
isReadOnlyprop. - data-indeterminate:
When the checkbox is indeterminate. Based on
isIndeterminateprop. - data-hover: When the checkbox is being hovered. Based on useHover
- data-focus: When the checkbox is being focused. Based on useFocusRing.
- data-focus-visible: When the checkbox is being focused with the keyboard. Based on useFocusRing.
- data-disabled:
When the checkbox is disabled. Based on
isDisabledprop. - data-loading:
When the checkbox is loading. Based on
isLoadingprop.
Accessibility
- Built with a native HTML
<input>element. - Full support for browser features like form autofill.
- Keyboard focus management and cross browser normalization.
- Keyboard event support for Tab and Space keys.
- Labeling support for assistive technology.
- Indeterminate state support.
API
Checkbox Props
| Prop | Type | Default |
children | | |
icon | | |
value | | |
name | | |
size | | "md" |
color | | "primary" |
radius | | |
lineThrough | | false |
isSelected | | |
defaultSelected | | |
isRequired | | false |
isReadOnly | | |
isDisabled | | false |
isIndeterminate | | |
isInvalid | | false |
validationState | | |
disableAnimation | | false |
classNames | |
Checkbox Events
| Prop | Type | Default |
onChange | | |
onValueChange | |

