Checkbox

Checkbox is a component used for allowing users to select multiple values from multiple options.

Usage

import { Checkbox, CheckboxGroup } from "@yamada-ui/react"
<Checkbox />
<CheckboxGroup.Root>
  <CheckboxGroup.Item />
</CheckboxGroup.Root>

Group

Use Items

Change Variant

Change Size

Set Default Value

To set a default value, set defaultValue to an array of values.

Default Checked

To default checked, set defaultChecked to true.

Indeterminate

To make indeterminate, set indeterminate to true.

Max Selection

To limit the maximum number of selections, set max to a number.

Change Direction

To change the direction, set orientation to "horizontal" or "vertical". The default is "vertical".

Change Shape

To change the shape, set shape to "rounded" or "square". The default is "rounded".

Disable

To disable, set disabled to true.

Read-Only

To read-only, set readOnly to true.

Invalid

To make invalid, set invalid to true.

Change Border Color

To change the border color, set focusBorderColor or errorBorderColor to a color value.

Customize Icon

To customize icon, set checkedIcon to a ReactNode.

Use Custom Component

Control

Props

Accessibility

The Checkbox follows the WAI-ARIA - Checkbox Pattern for accessibility.

If you are not using Field.Root, set aria-label or aria-labelledby to CheckboxGroup.Root.

<CheckboxGroup.Root aria-label="Character">
  <CheckboxGroup.Item value="sora">ソラ</CheckboxGroup.Item>
  <CheckboxGroup.Item value="riku">リク</CheckboxGroup.Item>
  <CheckboxGroup.Item value="kairi">カイリ</CheckboxGroup.Item>
</CheckboxGroup.Root>
<VStack gap="sm">
  <Text as="h3" id="label">
    Character
  </Text>

  <CheckboxGroup.Root aria-labelledby="label">
    <CheckboxGroup.Item value="sora">ソラ</CheckboxGroup.Item>
    <CheckboxGroup.Item value="riku">リク</CheckboxGroup.Item>
    <CheckboxGroup.Item value="kairi">カイリ</CheckboxGroup.Item>
  </CheckboxGroup.Root>
</VStack>

Keyboard Navigation

KeyDescriptionState
SpaceToggles the checked state of the focused checkbox.-

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
CheckboxGroup.Rootrole="group"Indicates that it's a group.
aria-labelledbyIf CheckboxGroup.Root is within a Field.Root and Field.Root has a label or Field.Label, sets its id.
aria-describedbyIf CheckboxGroup.Root is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
inputaria-checkedSets to "true" if the checkbox is checked, "false" if it is not checked, and "mixed" if indeterminate is set.
aria-describedbyIf Checkbox is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
aria-disabledSets to "true" if readOnly is set, or if the checkbox is not checked and max is reached in a group.
aria-invalidSets to "true" if invalid is set.
aria-requiredSets to "true" if required is set.
CheckboxIndicatoraria-hiddenExcludes the element from the accessibility tree.