stringCheckbox
The Checkbox component is used in forms when a user needs to select multiple
values from several options.
Native HTML checkboxes are 100% accessible by default, so we used a very common CSS technique to style the checkboxes.
Import#
import { Checkbox, CheckboxGroup } from "@chakra-ui/react"
Usage#
Basic usage of Checkbox.
Disabled Checkbox#
Checkbox with custom color#
You can override the color scheme of the Checkbox to any color key specified
in theme.colors.
Checkbox sizes#
Pass the size prop to change the size of the Checkbox. Values can be either
sm, md or lg.
Invalid Checkbox#
Changing the spacing#
We added the spacing prop to customize the spacing between the Checkbox and
label text.
<Checkbox spacing="1rem">Option</Checkbox>
Changing the icon color and size#
You can customize the color and size of the check icon by passing the
iconColor and iconSize prop.
<Checkbox iconColor="blue.400" iconSize="1rem">Option</Checkbox>
Indeterminate#
Icon#
CheckboxGroup#
Chakra exports a CheckboxGroup component to help manage the checked state of
its children Checkbox components and conveniently pass a few shared style
props to each. See the props table at the bottom of this page for a list of the
shared styling props.
Hooks#
The useCheckbox hook is exported with state and focus management logic for use
in creating tailor-made checkbox component for your application.
The useCheckboxGroup hook is exported with state management logic for use in
creating tailor-made checkbox group component for your application.
Props#
Checkbox Props#
aria-describedby
aria-describedbyaria-invalid
aria-invalidtruearia-label
aria-labelDefines the string that labels the checkbox element.
stringaria-labelledby
aria-labelledbyRefers to the id of the element that labels the checkbox element.
stringcolorScheme
colorScheme"whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram""blue"defaultIsChecked
defaultIsCheckedIf true, the checkbox will be initially checked.
@deprecated Please use the defaultChecked prop, which mirrors default
React checkbox behavior.
booleanicon
iconThe checked icon to use
React.ReactElementCheckboxIconiconColor
iconColorThe color of the checkbox icon when checked or indeterminate
stringiconSize
iconSizeThe size of the checkbox icon when checked or indeterminate
string | numberid
idid assigned to input
stringisChecked
isCheckedIf true, the checkbox will be checked.
You'll need to pass onChange to update its value (since it is now controlled)
booleanisDisabled
isDisabledIf true, the checkbox will be disabled
booleanisFocusable
isFocusableIf true and isDisabled is passed, the checkbox will
remain tabbable but not interactive
booleanisIndeterminate
isIndeterminateIf true, the checkbox will be indeterminate.
This only affects the icon shown inside checkbox
and does not modify the isChecked property.
booleanisInvalid
isInvalidIf true, the checkbox is marked as invalid.
Changes style of unchecked state.
booleanisReadOnly
isReadOnlyIf true, the checkbox will be readonly
booleanisRequired
isRequiredIf true, the checkbox input is marked as required,
and required attribute will be added
booleanname
nameThe name of the input field in a checkbox (Useful for form submission).
stringonChange
onChangeThe callback invoked when the checked state of the Checkbox changes.
((event: ChangeEvent<HTMLInputElement>) => void)onFocus
onFocusThe callback invoked when the checkbox is focused
((event: FocusEvent<HTMLInputElement>) => void)size
size"sm" | "md" | "lg""md"spacing
spacingThe spacing between the checkbox and its label text
SystemProps["marginLeft"]0.5remvalue
valueThe value to be used in the checkbox input. This is the value that will be returned on form submission.
string | numbervariant
variantVariants for Checkbox are not implemented in the default theme. You can extend the theme to implement them.
stringCheckboxGroup Props#
colorScheme
colorSchemeColor Schemes for CheckboxGroup are not implemented in the default theme. You can extend the theme to implement them.
"whiteAlpha" | "blackAlpha" | "gray" | "red" | "orange" | "yellow" | "green" | "teal" | "blue" | "cyan" | "purple" | "pink" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram"defaultValue
defaultValueThe initial value of the checkbox group
ReactText[]isDisabled
isDisabledIf true, all wrapped checkbox inputs will be disabled
booleanisNative
isNativeIf true, input elements will receive
checked attribute instead of isChecked.
This assumes, you're using native radio inputs
booleanonChange
onChangeThe callback fired when any children Checkbox is checked or unchecked
((value: ReactText[]) => void)size
size"sm" | "md" | "lg"value
valueThe value of the checkbox group
ReactText[]variant
variantVariants for CheckboxGroup are not implemented in the default theme. You can extend the theme to implement them.
stringShared Style Props#
The following style props can be set on CheckboxGroup and they will be
forwarded to all children Checkbox components.
| Name | Type | Default | Description |
|---|---|---|---|
| colorScheme | string | The color of the checkbox when it is checked. This should be one of the color keys in the theme (e.g."green", "red"). | |
| children | React.ReactNode | The content of the checkbox group. | |
| size | sm, md, lg | md | The size of the checkbox. |
| variant | string | The variant of the checkbox. |