Loading...
Skip to main content

Checkbox

Checkbox wraps a native checkbox input with customizable appearance for presenting toggleable options.

Basic checkbox

Checkbox applies its themed appearance to the native input. This does the following:

  • Overrides the default <input> appearance with themed colors.
  • Renders the :checked and indeterminate icons via a CSS mask on the input’s ::before pseudo-element, so the mark inherits the contrast color and no inline SVG is needed. The appropriate icon is shown based on the input’s state.

For folks looking to replace our provided icons, override the --bs-check-icon-checked and --bs-check-icon-indeterminate CSS variables with your own mask-image URLs.

Labels and layout are handled with additional HTML and CSS.

<Checkbox
defaultChecked
id="check"
/>

Indeterminate

Checkboxes can utilize the indeterminate pseudo class. There is no available HTML attribute for specifying it; the indeterminate prop sets the native JavaScript property.

<Checkbox
id="checkIndeterminate"
indeterminate
/>

With form field

Wrap Checkbox in a FormField layout wrapper and add your label. The grid layout places the checkbox and label side by side.

<FormField>
<Checkbox id="checkLabel" />
<FormLabel
htmlFor="checkLabel"
plain
>
Example new checkbox
</FormLabel>
</FormField>

Description

Add a description or other content after the label. Wrap the label and description in FormFieldContent to ensure appropriate spacing and alignment.

Supporting description for the above label.
<FormField>
<Checkbox id="checkDescription" />
<FormFieldContent>
<FormLabel
htmlFor="checkDescription"
plain
>
Example new checkbox
</FormLabel>
<FormText>
Supporting description for the above label.
</FormText>
</FormFieldContent>
</FormField>

Theme colors

Modify the appearance of checked checkboxes with the theme prop. This will set the checked background and border color to the theme color.

<div className="d-flex flex-column gap-2">
<FormField>
<Checkbox
defaultChecked
id="checkprimary"
theme="primary"
/>
<FormLabel
htmlFor="checkprimary"
plain
>
Example primary checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkaccent"
theme="accent"
/>
<FormLabel
htmlFor="checkaccent"
plain
>
Example accent checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checksecondary"
theme="secondary"
/>
<FormLabel
htmlFor="checksecondary"
plain
>
Example secondary checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checksuccess"
theme="success"
/>
<FormLabel
htmlFor="checksuccess"
plain
>
Example success checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkdanger"
theme="danger"
/>
<FormLabel
htmlFor="checkdanger"
plain
>
Example danger checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkwarning"
theme="warning"
/>
<FormLabel
htmlFor="checkwarning"
plain
>
Example warning checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkinfo"
theme="info"
/>
<FormLabel
htmlFor="checkinfo"
plain
>
Example info checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkdark"
theme="dark"
/>
<FormLabel
htmlFor="checkdark"
plain
>
Example dark checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checklight"
theme="light"
/>
<FormLabel
htmlFor="checklight"
plain
>
Example light checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkinverse"
theme="inverse"
/>
<FormLabel
htmlFor="checkinverse"
plain
>
Example inverse checkbox
</FormLabel>
</FormField>
</div>

Disabled

Set the disabled prop on Checkbox; its associated FormLabel is automatically styled in a lighter color to indicate the input's state.

<Stack gap={2}>
<FormField>
<Checkbox
disabled
id="checkDisabled"
/>
<FormLabel
htmlFor="checkDisabled"
plain
>
Example new checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
disabled
id="checkDisabledChecked"
/>
<FormLabel
htmlFor="checkDisabledChecked"
plain
>
Example new checkbox
</FormLabel>
</FormField>
</Stack>

Sizes

Set size="sm" or size="lg" to make your checkbox appear smaller or larger.

<div className="d-flex flex-column gap-3">
<FormField>
<Checkbox
defaultChecked
id="checkSizeSm"
size="sm"
/>
<FormLabel
htmlFor="checkSizeSm"
plain
>
Small checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkSizeMd"
/>
<FormLabel
htmlFor="checkSizeMd"
plain
>
Default checkbox
</FormLabel>
</FormField>
<FormField>
<Checkbox
defaultChecked
id="checkSizeLg"
size="lg"
/>
<FormLabel
htmlFor="checkSizeLg"
plain
>
Large checkbox
</FormLabel>
</FormField>
</div>

CSS

Variables

Override the checkbox component's CSS variables for visual customization.

.example {
--bs-check-size: 1.25rem;
--bs-check-margin-block: 0.125rem;
--bs-check-bg: var(--bs-bg-body);
--bs-check-border-color: var(--bs-border-color);
--bs-check-border-radius: var(--bs-radius-5);
--bs-check-icon-checked: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m5.5 10 3 3 6-6'/%3e%3c/svg%3e");
--bs-check-icon-indeterminate: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='black' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 10h8'/%3e%3c/svg%3e");
--bs-check-checked-bg: var(--bs-control-checked-bg);
--bs-check-checked-border-color: var(--bs-control-checked-border-color);
--bs-check-indeterminate-bg: var(--bs-control-checked-bg);
--bs-check-indeterminate-border-color: var(--bs-control-checked-border-color);
--bs-check-active-bg: var(--bs-control-active-bg);
--bs-check-active-border-color: var(--bs-control-active-border-color);
--bs-check-disabled-bg: var(--bs-control-disabled-bg);
--bs-check-disabled-opacity: var(--bs-control-disabled-opacity);
}
Documentation navigation
On this page
On this page