Checkbox | Mantine

Capture boolean input from user

Use checked and onChange props to control Checkbox state:

Set the readOnly prop to prevent the checkbox value from being changed by user interaction. The checkbox still displays its current value and reflects programmatic updates to the checked prop, but clicking it (or pressing Space ) does not toggle its state and does not call the onChange handler:

Example of using Checkbox with @mantine/form :

Checkbox can be used with uncontrolled forms the same way as native input[type="checkbox"] . Set the name attribute to include checkbox value in FormData object on form submission. To control initial checked state in uncontrolled forms, use defaultChecked prop.

Example usage of uncontrolled Checkbox with FormData :

Use the error prop to display error message below the checkbox label. If you want to apply error styles to checkbox without error message, user boolean error prop. If you want to display error message without applying error styles, set withErrorStyles={false} .

Use the iconColor prop to change the icon color. You can reference colors from theme.colors or use any valid CSS color:

Checkbox supports indeterminate state. When the indeterminate prop is set, the checked prop is ignored (checkbox always has checked styles):

You can change the target element to which the tooltip is attached with refProp :

By default, checkbox input and label have cursor: default (same as native input[type="checkbox"] ). To change the cursor to pointer, set cursorType on theme :

Checkbox supports the autoContrast prop and theme.autoContrast . If autoContrast is set either on Checkbox or on the theme, the content color will be adjusted to have sufficient contrast with the value specified in the color prop.

Note that the autoContrast feature works only if you use the color prop to change the background color. autoContrast works only with the filled variant.

You can add any number of custom sizes with data-size attribute:

All props passed to the component are forwarded to the input element. If you need to add props to the root element, use wrapperProps . In the following example:

Checkbox.Group manages the state of multiple checkboxes, it accepts value and onChange props, which are used to control the state of checkboxes inside the group. The value prop should be an array of strings, where each string is the value of a checkbox. The onChange prop should be a function that receives the new value as an array of strings.

Checkbox.Group component supports all Input.Wrapper props.

Use maxSelectedValues prop to limit the number of selected values in Checkbox.Group . When the limit is reached, the remaining checkboxes are disabled and cannot be selected.

Example of using Checkbox.Group with @mantine/form :

Checkbox.Group can be used with uncontrolled forms, it renders a hidden input which joins all checked values into a single string using hiddenInputValuesSeparator prop.

Props for usage with uncontrolled forms:

Checkbox.Indicator looks exactly the same as the Checkbox component, but it does not have any semantic meaning, it's just a visual representation of checkbox state. You can use it in any place where you need to display checkbox state without any interaction related to the indicator. For example, it is useful in cards based on buttons, trees, etc.

Note that Checkbox.Indicator cannot be focused or selected with keyboard. It is not accessible and should not be used as a replacement for the Checkbox component.

Checkbox.Card component can be used as a replacement for Checkbox to build custom cards/buttons/other things that work as checkboxes. The root element of the component has role="checkbox" attribute, it is accessible by default and supports the same keyboard interactions as input[type="checkbox"] .

You can use Checkbox.Card with Checkbox.Group the same way as the Checkbox component:

Choose all packages that you will need in your application

The example above shows how to get ref of the checkbox input element. To get ref of the root element, use rootRef prop:

Checkbox supports the Styles API ; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.

Checkbox description

Component Styles API

Hover over selectors to highlight corresponding elements

Most of the Checkbox props are passed down to the input element. If you want to pass props to the root element instead, use wrapperProps prop.

By default, Checkbox generates a random id attribute for the input element to associate it with the label. You can supply your own id attribute with id prop. It will be used in id attribute of the input element and htmlFor attribute of the label element.

Checkbox component is based on the native input[type="checkbox"] element, so it is accessible by default.

Set aria-label or label prop to make the checkbox accessible for screen readers:

Recommended articles