shadcn.io is not affiliated with official shadcn/ui
Checkbox examples · Standard
Custom Indicator Checkbox for React
A checkbox restyled to turn green when checked, with classes keyed to its checked state.
The default checkbox fills with the primary color when checked; this one fills green. The classes on the Checkbox only apply in the checked state, so the box is a normal outline until it's ticked, then takes the success color for its border and fill while the check icon stays as it is. Use it for confirmations, completed steps or any place where the checked state should read as success.
Preview
Installation
FAQ
How do I change checkbox colors?
Prefix the classes with the checked variant so they only apply when the box is ticked, here bg-success and border-success. Your classes override the checkbox's own, and no conditional logic is needed. The success color is a theme token: add --success to your theme if it doesn't have one, or use another token like primary or destructive.
The box carries a data-checked attribute, which the data-checked: variant matches.
Can I use different icons instead of Check?
The Checkbox draws its own indicator, a Lucide CheckIcon, and doesn't take one as children. To use another icon, edit the indicator in the checkbox file in your components/ui folder, or add a variant there for the boxes that need it.
How do I make custom-styled checkboxes larger or smaller?
Add a size class to the Checkbox, such as size-5. The check icon's size is set in the checkbox's styles, so for a much larger box enlarge the icon there too. Bigger boxes help on touch screens; in dense tables the default size is usually right.
Can I create theme-based checkbox color schemes?
Yes: use theme tokens rather than fixed colors. bg-success reads the --success variable, so light and dark themes can each set their own green. To change every checkbox, edit the checked classes in the checkbox file instead of repeating them on each one.
Related
- Simple CheckboxA checkbox with a label for a single
- Todo Style CheckboxA to-do item whose label is struck
- Indeterminate CheckboxA checkbox that starts indeterminate, the
- With Subtitle CheckboxA checkbox whose label has a short muted
- Vertical List CheckboxA stacked list of programming language
- Nested List CheckboxA select-all checkbox over three indented