How it works
One file, two components. Checkbox is a <label> around a transparent native input that covers it, so clicks, Space, screen readers and form submission all work natively; the box, tick and dash are decoration behind it. The empty box is white with a soft inner ring; checked it fills with the accent and the tick draws from start to end, while the indeterminate dash grows from the middle. Pressing dips the box and release springs it back past 1×. Rings and the focus halo are box-shadows, so state never changes size. CheckboxGroup renders options and returns values in options order.
Use it for
- Choosing zero or more options: filters, permissions, notification preferences.
- A single yes or no that takes effect on submit: agreeing to terms, remembering a login.
- A select-all above a list, using indeterminate for a partial selection.
Look elsewhere when
- Only one choice allowed: use a radio group.
- Settings that apply immediately, such as dark mode: use a switch; a checkbox means “applies on submit”.
- More than about 8 options, or options that need search: use a multi-select dropdown.
Usage
import { useState } from 'react'
import { Checkbox, CheckboxGroup } from './Checkbox.jsx'
// Single: agree to terms (uncontrolled; submits agree=on with the form)
export function Agreement() {
return <Checkbox name="agree" label="I have read and agree to the terms" required />
}
// A group with select-all: the master box controls only the enabled options
const TOPICS = [
{ value: 'news', label: 'Product news' },
{ value: 'tips', label: 'Tips and tutorials' },
{ value: 'beta', label: 'Beta programme', description: 'Currently full', disabled: true },
]
const OPEN = TOPICS.filter((t) => !t.disabled).map((t) => t.value)
export function Topics() {
const [picked, setPicked] = useState(['news'])
const count = OPEN.filter((v) => picked.includes(v)).length
return (
<>
<Checkbox
label="All topics"
checked={count === OPEN.length}
indeterminate={count > 0 && count < OPEN.length}
onChange={(checked) => setPicked(checked ? OPEN : [])}
/>
<CheckboxGroup label="Email topics" options={TOPICS} value={picked} onChange={setPicked} />
</>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
checked | boolean | — | Checkbox: controlled checked state. Use it together with onChange. |
defaultChecked | boolean | false | Checkbox: initial state when uncontrolled. |
onChange | (checked, event) => void | — | Checkbox: called when the state changes; the second argument is the native event. |
indeterminate | boolean | false | Checkbox: shows a dash and is announced as mixed. Visual only; it does not change checked. |
label | ReactNode | — | Checkbox: label text; clicking it also toggles. Give aria-label when omitted. |
description | ReactNode | — | Checkbox: help text under the label, read after the label. |
size | 'sm' | 'md' | 'lg' | 'md' | Both components. Box 18 / 20 / 24px with 5 / 6 / 7px corners, label 13 / 14 / 16px. Use lg on mobile. |
invalid | boolean | false | Both components. Error: an unchecked box gets a danger ring and a faint danger tint, and aria-invalid is set. |
disabled | boolean | false | Both components. Disabled: 45% opacity and not clickable; on CheckboxGroup it disables the whole group. |
className / style | string / CSSProperties | — | Checkbox: applied to the root <label>. |
...rest | InputHTMLAttributes | — | Checkbox: other attributes (name, value, required, aria-*) go to the native input; the ref points to it too. |
options | { label, value, description?, disabled? }[] | — | CheckboxGroup: the options; value is a string or number. |
value | any[] | — | CheckboxGroup: controlled array of checked values. |
defaultValue | any[] | [] | CheckboxGroup: initially checked values when uncontrolled. |
onChange | (value) => void | — | CheckboxGroup: called with the checked values in options order; values missing from options are kept. |
direction | 'vertical' | 'horizontal' | 'vertical' | CheckboxGroup: vertical (14px between rows) or horizontal (20px gap, wraps when full). |
name | string | — | CheckboxGroup: form field name; each checked option submits name=value. |
label | string | — | CheckboxGroup: accessible name of the group. With a visible title, pass aria-labelledby instead. |
...rest | HTMLAttributes | — | CheckboxGroup: other attributes go to the root <div role="group">. |
Accessibility
- A native <input type="checkbox">: Tab to focus, Space to toggle, announced as checked or unchecked, and as mixed when indeterminate.
- Label and description are linked with aria-labelledby and aria-describedby; clicking the label text toggles.
- A focus ring shows on keyboard focus; in forced-colors mode it becomes an outline and checked uses the system highlight.
- State is not colour alone: tick and dash are shapes, and invalid also sets aria-invalid.
- CheckboxGroup is role="group" named by label or aria-labelledby; on touch screens each item is at least 44px tall.
Motion
The tick draws in 240ms ease-out (40ms after the fill) and retracts in 100ms; the dash grows from the middle in 160ms. The fill changes in 160ms and the focus halo grows in over 220ms. Pressing dips the box to 0.86 in 100ms; release springs it back in 380ms with a slight overshoot.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
Checkbox.jsxcheckbox.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





