Checkbox
Import
import { Checkbox } from "@cfa/react-core";Live Editor
Examples
Default Selected
The defaultSelected prop allows you to set the initial state of the checkbox.
Description
The description prop allows you to add helper text to the checkbox.
Disabled
Use the isDisabled prop to disable the checkbox.
Indeterminate
A checkbox input can only have two states in a form: checked or unchecked. It either submits its value or doesn’t. However, visually there are three states a checkbox can be in: checked, unchecked, or indeterminate. Below is an example of the indeterminate state, passing the isIndeterminate prop.
Invalid
The isInvalid prop applies the following outline error color to a validated Checkbox.
Readonly
The isReadOnly prop applies the following visual style and prevents user from making a selection.
Readonly inputs are still focusable (MDN spec).
Required
The isRequired prop applies a red asterisk to the label, visually indicating that the checkbox is required.
Success
The isSuccess prop should only be used on the individual Checkbox, not all checkboxes in a group.
Controlled
Use the isSelected or defaultSelected prop to set the selection state, and onChange to handle selection changes.
Props
Visit the Documentation Site for the full list of props.
| Name | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | ReactElement<unknown, string | JSXElementConstructor<any>> | - | The label of the checkbox. |
| description | string | - | Additional helper text for the checkbox. |
| isSuccess | boolean | false | Sets the checkbox to a success state. |
| ref | Ref<HTMLLabelElement> | - | Requires React 19 |
| aria-controls | string | - | Identifies the element (or elements) whose contents or presence are controlled by the current element. |
| aria-describedby | string | - | Identifies the element (or elements) that describes the object. |
| aria-details | string | - | Identifies the element (or elements) that provide a detailed, extended description for the object. |
| aria-errormessage | string | - | Identifies the element that provides an error message for the object. |
| aria-label | string | - | Defines a string value that labels the current element. |
| aria-labelledby | string | - | Identifies the element (or elements) that labels the current element. |
| autoFocus | boolean | - | Whether the element should receive focus on render. |
| className | ClassNameOrFunction<CheckboxRenderProps> | 'react-aria-Checkbox' | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| defaultSelected | boolean | - | Whether the element should be selected (uncontrolled). |
| dir | string | - | - |
| excludeFromTabOrder | boolean | - | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
| form | string | - | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). |
| hidden | boolean | - | - |
| id | string | - | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). |
| inert | boolean | - | - |
| inputRef | RefObject<HTMLInputElement> | - | A ref for the HTML input element. |
| isDisabled | boolean | - | Whether the input is disabled. |
| isIndeterminate | boolean | - | Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. |
| isInvalid | boolean | - | Whether the input value is invalid. |
| isReadOnly | boolean | - | Whether the input can be selected but not changed by the user. |
| isRequired | boolean | - | Whether user input is required on the input before form submission. |
| isSelected | boolean | - | Whether the element should be selected (controlled). |
| lang | string | - | - |
| name | string | - | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). |
| onAnimationEnd | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAnimationEndCapture | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAnimationIteration | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAnimationIterationCapture | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAnimationStart | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAnimationStartCapture | AnimationEventHandler<HTMLLabelElement> | - | - |
| onAuxClick | MouseEventHandler<HTMLLabelElement> | - | - |
| onAuxClickCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onBlur | (e: FocusEvent<Element, Element>) => void | - | Handler that is called when the element loses focus. |
| onChange | (isSelected: boolean) => void | - | Handler that is called when the element's selection state changes. |
| onClick | (e: MouseEvent<FocusableElement, MouseEvent>) => void | - | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. |
| onClickCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onContextMenu | MouseEventHandler<HTMLLabelElement> | - | - |
| onContextMenuCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onDoubleClick | MouseEventHandler<HTMLLabelElement> | - | - |
| onDoubleClickCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onFocus | (e: FocusEvent<Element, Element>) => void | - | Handler that is called when the element receives focus. |
| onFocusChange | (isFocused: boolean) => void | - | Handler that is called when the element's focus status changes. |
| onGotPointerCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onGotPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onHoverChange | (isHovering: boolean) => void | - | Handler that is called when the hover state changes. |
| onHoverEnd | (e: HoverEvent) => void | - | Handler that is called when a hover interaction ends. |
| onHoverStart | (e: HoverEvent) => void | - | Handler that is called when a hover interaction starts. |
| onKeyDown | (e: KeyboardEvent) => void | - | Handler that is called when a key is pressed. |
| onKeyUp | (e: KeyboardEvent) => void | - | Handler that is called when a key is released. |
| onLostPointerCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onLostPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onMouseDown | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseDownCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseEnter | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseLeave | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseMove | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseMoveCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseOut | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseOutCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseOver | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseOverCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseUp | MouseEventHandler<HTMLLabelElement> | - | - |
| onMouseUpCapture | MouseEventHandler<HTMLLabelElement> | - | - |
| onPointerCancel | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerCancelCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerDown | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerDownCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerEnter | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerLeave | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerMove | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerMoveCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerOut | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerOutCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerOver | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerOverCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerUp | PointerEventHandler<HTMLLabelElement> | - | - |
| onPointerUpCapture | PointerEventHandler<HTMLLabelElement> | - | - |
| onPress | (e: PressEvent) => void | - | Handler that is called when the press is released over the target. |
| onPressChange | (isPressed: boolean) => void | - | Handler that is called when the press state changes. |
| onPressEnd | (e: PressEvent) => void | - | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. |
| onPressStart | (e: PressEvent) => void | - | Handler that is called when a press interaction starts. |
| onPressUp | (e: PressEvent) => void | - | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. |
| onScroll | UIEventHandler<HTMLLabelElement> | - | - |
| onScrollCapture | UIEventHandler<HTMLLabelElement> | - | - |
| onTouchCancel | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchCancelCapture | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchEnd | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchEndCapture | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchMove | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchMoveCapture | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchStart | TouchEventHandler<HTMLLabelElement> | - | - |
| onTouchStartCapture | TouchEventHandler<HTMLLabelElement> | - | - |
| onTransitionCancel | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionCancelCapture | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionEnd | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionEndCapture | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionRun | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionRunCapture | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionStart | TransitionEventHandler<HTMLLabelElement> | - | - |
| onTransitionStartCapture | TransitionEventHandler<HTMLLabelElement> | - | - |
| onWheel | WheelEventHandler<HTMLLabelElement> | - | - |
| onWheelCapture | WheelEventHandler<HTMLLabelElement> | - | - |
| render | DOMRenderFunction<"label", CheckboxRenderProps> | - | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: * You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). * Only a single root DOM element can be rendered (no fragments). * You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. |
| slot | string | - | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. |
| style | StyleOrFunction<CheckboxRenderProps> | - | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. |
| translate | "yes" | "no" | - | - |
| validate | (value: boolean) => true | ValidationError | - | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead. |
| validationBehavior | "native" | "aria" | 'native' | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
| value | string | - | The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue). |