Playground

Checkbox

A box to turn one choice on or off, with an indeterminate state.

  • Built on radix-ui/Checkbox
  • role=checkbox; Space toggles; Tab focuses.
  • indeterminate is exposed as aria-checked=mixed.
  • A visible label is clickable; without one, aria-label is required.
  • Styles in one file: checkbox.css

Import

import '@monoline/css';
import {Checkbox} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add checkbox

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {Checkbox} from '@monoline/react';

<div style={{display: 'grid', gap: 'var(--s3)'}}>
  <Checkbox label="Replies" defaultChecked />
  <Checkbox label="Mentions" />
  <Checkbox label="Billing (locked)" disabled />
</div>

Examples

Basic

Indeterminate

Props

CheckboxProps

PropTypeDefaultDescription
labelReactNode–Visible label. Without it, give the checkbox an `aria-label`.
invalidboolean–Marks the checkbox as having an error: sets `aria-invalid` and shows the error border.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-invalid="true"]checkbox.css
[data-orientation="horizontal"]checkbox.css
[data-state="checked"]checkbox.css
[data-state="indeterminate"]checkbox.css

CSS classes

ClassStylesheet
.checkboxcheckbox.css
.checkbox-markcheckbox.css
.radiocheckbox.css
.radio-dotcheckbox.css
.radio-groupcheckbox.css
.swcheckbox.css
.sw-thumbcheckbox.css
.choice10-choices.css
.choice-group10-choices.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.checkbox {
  border-color: var(--accent);
}
.checkbox[aria-invalid="true"] {
  background: var(--wash);
}

Try the props

Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.

example.tsx
<Checkbox label="Email me updates" />

Accessibility

  • role=checkbox; Space toggles; Tab focuses.
  • indeterminate is exposed as aria-checked=mixed.
  • A visible label is clickable; without one, aria-label is required.

Keyboard

KeysAction
SpaceToggles
TabFocuses