forms

Tailwind CSS Checkbox

The checkbox component allows users to select one or more options by ticking a square box, available in various styles, sizes, colors, and variants.

Class Name
Type
Description
checkboxComponentComponent class for checkbox.
form-controlComponentContainer element.
labelComponentFor helper text.
custom-optionComponentFor custom checkbox container.
custom-label-optionComponentFor custom checkbox container with background.
checkbox-primaryModifierAdds ‘primary’ color to checkbox.
checkbox-secondaryModifierAdds ‘secondary’ color to checkbox.
checkbox-accentModifierAdds ‘accent’ color to checkbox.
checkbox-infoModifierAdds ‘info’ color to checkbox.
checkbox-successModifierAdds ‘success’ color to checkbox.
checkbox-warningModifierAdds ‘warning’ color to checkbox.
checkbox-errorModifierAdds ’error’ color to checkbox.
is-validModifierAdds success style to the input.
is-invalidModifierAdds error style to the input.
checkbox-xsResponsiveCheckbox with extra small size.
checkbox-smResponsiveCheckbox with small size.
checkbox-lgResponsiveCheckbox with large size.

Basic checkbox example.

Utilize the form-control component class in conjunction with a label tag and implement styling using Tailwind CSS classes.

Apply a semantic color to the checkbox by using the checkbox-{semantic-color} modifier class together with the checkbox component class.

To customize the background color, use the CSS variable --chkbg, and to customize the foreground color, use the CSS variable --chkfg.

Resize a checkbox by applying the checkbox-xs, checkbox-sm or checkbox-lg responsive classes to adjust its size to either extra-small, small or large.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

Prevent user interaction with the checkbox by adding the disabled attribute to make it non-selectable.

The indeterminate state can be configured using JavaScript. To gain further insight into this concept, you can explore more about it here.

A group of checkbox components.

A vertical group of checkbox components.

Below example shows a checkbox in dropdown.

This example can be used to show a list of checkbox buttons inside a grouped list.

Use this example to group up checkbox button components inside a list.

Utilizing the custom-option class within the label enables the creation of custom checkbox buttons with improved styling and functionality.

Utilize the hidden utility class to conceal the checkbox button.

Utilizing the custom-label-option class within the label demonstrates this distinctive styling approach, where the label background becomes primary when checked.

Customize the checkbox styling using utility classes according to your preferences, as illustrated below.

This example displays an image as a checkbox button.