Skip to content
shadcn.io

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.

Framework
UI library

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

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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.

Do custom colors affect checkbox accessibility?

They can. The checked box needs enough contrast against the page (3:1 for UI parts) and the check needs enough against the fill. The check icon itself is the non-color cue that the box is ticked, so keep it.

Can I use different colors for different checkbox purposes?

Yes, if the colors carry meaning and stay consistent: green for confirmations, destructive for choices like "delete my data". Don't vary colors for decoration, and never let color be the only signal: the label has to say what the box does.