Close
Angular React Web Components Blazor React
Open Source

React Checkbox Component

The React Checkbox is a component that lets you add checkboxes to your React apps. It behaves as a standard HTML checkbox, enabling users to select basic checked and unchecked states or an additional indeterminate state. You also get full control over the styling of the React checkbox component and ability to use it with forms.

Live Demo

Anatomy

The React Checkbox renders a selectable control with an optional label.

Checkbox anatomy showing the indicator and optional label
1. Checkbox Indicator: indicates the current state. By default it is unselected. Could be before or after the label
2. Label (optional): specifies the target data available for selection and deselection

The React Checkbox consists of an indicator and optional label content. Set the label position when the label should appear before or after the indicator.

Checkbox
├── Checkbox Indicator
└── Label (optional)

Getting Started

To use the React Checkbox, follow the Ignite UI for React Getting Started topic for the basic project setup, then install or register the component for your target platform.

Using the **** package, install the package before importing the Checkbox wrapper:

npm install igniteui-react

Then import the React Checkbox wrapper and the theme CSS:

import { IgrCheckbox } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';

After registration, render the IgrCheckbox with the platform-specific element or wrapper:

<IgrCheckbox></IgrCheckbox>

Usage

At its core, the IgrCheckbox lets users choose between selected and unselected states, with support for an indeterminate state when an option represents a partial selection.

You can specify if the label should be positioned before or after the checkbox toggle by setting the LabelPosition attribute of the checkbox. Allowed values are before and after (default):

<IgrCheckbox labelPosition="before"></IgrCheckbox>

The checkbox can also be labelled by elements external to the checkbox. In this case, the user is given full control to position and style the label in accordance with their needs.

  <span id="checkbox-label">Label</span>
  <IgrCheckbox aria-labelledby="checkbox-label" labelPosition="before"></IgrCheckbox>

States

The Checkbox supports different state-related attributes. You can use the checked attribute to set the initial state of the checkbox to on or off.

<IgrCheckbox checked={true}></IgrCheckbox>

You can use the indeterminate attribute to set the checkbox’s value to neither true nor false.

<IgrCheckbox indeterminate={true}></IgrCheckbox>

You can use the disabled attribute to disable the Checkbox.

<IgrCheckbox disabled={true}></IgrCheckbox>

You can use the invalid attribute to mark the Checkbox as invalid.

<IgrCheckbox invalid={true}></IgrCheckbox>

You can use the required property to mark the Checkbox as required.

<IgrCheckbox required={true}></IgrCheckbox>

Do/Don’t

When many Checkboxes are necessary, arrange them in a column group so users can quickly scan the list. Fewer Checkboxes may be arranged on a single line next to each other, but avoid arranging them in multiple columns.

Checkboxes arranged in a single vertical column Checkboxes arranged in multiple columns

Do

Stack checkboxes vertically in a single column to make options easy to scan and read.

Don’t

Avoid arranging checkboxes into multiple columns, as this breaks vertical reading patterns and makes scanning difficult.

Properties

The following properties cover the main Checkbox configuration options documented on this page. See the full API reference for the complete generated list.

Name Type Default Description
checked boolean false Gets or sets whether the checkbox is selected.
indeterminate boolean false Gets or sets whether the checkbox is in an indeterminate state.
labelPosition ToggleLabelPosition after Sets the position of the checkbox label.
required boolean false Gets or sets whether the Checkbox is required.
invalid boolean false Gets or sets whether the Checkbox is invalid.
disabled boolean false Gets or sets whether the Checkbox is disabled.
value string — Gets or sets the value used when the Checkbox is submitted with a form.
name string — Gets or sets the name used when the Checkbox is submitted with a form.

Styling

The React Checkbox uses CSS parts and CSS variables to customize its appearance.

Sass Theming

Use the Ignite UI for React theme system to style the Checkbox consistently with the rest of your application. Verify the available Sass theme parameters in the API documentation before adding a custom theme.

CSS Variables

Use the following styling properties to customize the Checkbox indicator and selected-state appearance:

Variable What it changes
--tick-color The color of the check icon.
--fill-color The background color of the selected checkbox.

Style Parts

Use the following CSS parts to target the Checkbox structure:

Part What it styles
base The base wrapper of the Checkbox.
control The checkbox control element.
indicator The checkbox indicator icon.
label The Checkbox label.

Custom Styling

The following selectors customize the Checkbox indicator color and selected-state fill:

Selector Declaration Effect
igc-checkbox::part(indicator) --tick-color Changes the check icon color.
igc-checkbox::part(control checked)::after --fill-color Changes the selected checkbox background color.
igc-checkbox::part(indicator) {
  --tick-color: var(--ig-secondary-500-contrast); /* check icon color */
}
igc-checkbox::part(control checked)::after {
  --fill-color: var(--ig-secondary-500); /* checkbox background color */
}

Styling with Tailwind

You can style the React Checkbox with the custom Tailwind utility classes from igniteui-theming. Make sure to set up Tailwind first, then import the Ignite UI utilities in your global stylesheet:

@import "tailwindcss";
@import "igniteui-theming/tailwind/utilities/material.css";
<IgrCheckbox className="![--tick-color:var(--ig-secondary-500)]" />

The exclamation mark (!) gives the Tailwind utility precedence over the Checkbox’s default theme styles.

Accessibility

The React Checkbox provides a selectable control with a label and state that must remain understandable for keyboard and assistive technology users.

Keyboard Interaction

The Checkbox uses the keyboard behavior provided by its rendered control. A disabled Checkbox is not keyboard interactive, and the Space key changes its checked state.

Use the keyboard interaction provided by the Checkbox and verify the focus and state-change behavior for the target platform.

Key / interaction Action
Tab / Shift+Tab Moves focus to or away from the Checkbox when it is enabled and focusable.
Space Toggles the checked state of the focused Checkbox.
Indeterminate state The Checkbox exposes its current state when the indeterminate state is enabled.

Screen Readers / ARIA

The Checkbox exposes its checked state, disabled state, and, when configured, required, invalid, and indeterminate states through the semantics of its rendered control.

  • Provide meaningful label content for every Checkbox so assistive technology users can identify its purpose.
  • When the label is outside the component, connect it with the supported labelling mechanism and verify the announcement in the target platform.
  • Preserve the Checkbox state semantics when customizing or wrapping the control.
  • Change event handlers report state changes; they do not replace the accessible name or state.

The checked, unchecked, required, invalid, disabled, and indeterminate states must remain available to assistive technology through the component’s supported semantics. Verify the rendered announcement against the platform API documentation.

Accessibility Compliance

Verify the rendered React Checkbox against the accessibility requirements of the application.

Criterion How the component supports the requirement
2.1.1 Keyboard The enabled Checkbox can receive keyboard focus and its checked state can be changed with Space.
4.1.2 Name, Role, Value The Checkbox exposes its accessible name and current selection state through the rendered control and supported state semantics.
3.3.1 Error Identification When the Checkbox is invalid, expose the validation state and provide an appropriate message in the surrounding form.

Your responsibilities:

  • Give every Checkbox a meaningful accessible name.
  • Keep focus visible and preserve sufficient contrast when customizing the Checkbox theme.
  • Ensure required, invalid, disabled, and indeterminate states are also communicated when visual styling alone is insufficient.
  • Test the rendered Checkbox with keyboard navigation and supported assistive technologies.

API References

Dependencies

The React Checkbox requires a theme stylesheet to apply its visual styling. See the framework-specific setup in Getting Started.

Additional Resources

Use the following React resources for API details and project support:

The React Checkbox is intended for selectable form options. Use the following related component when you need an immediate on/off action instead:

FAQ

These frequently asked questions cover common React Checkbox selection, accessibility, form, and validation scenarios.

Can I use the Checkbox with a form?

The React Checkbox is form-associated and participates in a native HTML <form>. Set a unique name and a value so the checked state is submitted with the form.

How do I show a partially selected Checkbox?

The React Checkbox supports a third, indeterminate state for partially selected options. Set the indeterminate property to enable that state.

How do I provide an accessible Checkbox label?

The React Checkbox should have meaningful label content so assistive technology users can identify its purpose. When the label is outside the component, connect it with the supported labelling mechanism such as aria-labelledby.

How do I mark a Checkbox as required or invalid?

Set the required property to indicate that the Checkbox must be selected and the invalid property to expose a validation state. Provide an appropriate validation message in the surrounding form when the Checkbox is invalid.