Use for a choice applied when a form is submitted, for selecting table rows, and for a tri-state select-all parent. CheckboxField adds label, description and error.
When not to use
For an instant on/off setting use Switch. For exactly one choice among several use Radio Group.
Use a checkbox for a choice that is applied when a form is submitted, for selecting rows in a table,
and for a "select all" parent over a list of options. For a setting that takes effect immediately,
use a switch instead.
Pressing charges the box: it sinks under the pointer. Checking is the action: a primary
circle grows from the press point (from the centre for the keyboard) while the corners round toward
a circle and square back, and the tick draws itself. The box then settles with a small
overshoot. Indeterminate is a short pill that stretches into the fill when checked. How much of each
beat you see depends on the temperament: calm has no overshoot and rounds the corners only a
little, playful rounds them fully.
The demo is the most common place for a checkbox in a product: selecting rows in a table. The
header checkbox shows how much of the list is ticked (its pill grows with ratio), and a bulk bar
takes the footer's place while rows are selected.
CheckboxField is the checkbox with its label, description and error in one row. The whole row is
the hit target (at least 44px tall) and the error links itself with aria-describedby.
import { CheckboxField } from "@/components/ui/checkbox"export function Terms({ attempts, accepted, onAcceptedChange }: TermsProps) { return ( <CheckboxField name="terms" required label="I accept the billing terms" description="Renews every year. Cancel any time from Billing." error={attempts > 0 && !accepted ? "Accept the terms to continue." : undefined} refuseKey={attempts} checked={accepted} onCheckedChange={(next) => onAcceptedChange(next === true)} /> )}
The bare Checkbox takes a <label htmlFor> or an aria-label, for table cells and custom layouts:
import { Checkbox } from "@/components/ui/checkbox";<div className="flex items-center gap-3"> <Checkbox id="terms" name="terms" required /> <label htmlFor="terms" className="text-sm"> I accept the billing terms </label></div>
Controlled, with a tri-state "select all" parent. A check caused by the parent waits one stagger
step per cascadeIndex (capped at 12); a checkbox's own press never waits.
Pass ratio (selected / total) to the parent and its indeterminate pill shows how much of the list
is ticked, from a short dash to almost full.
error on CheckboxField (or invalid on Checkbox) turns the rim and halo destructive and
the box kicks sideways once: the refuse beat. Change refuseKey on every submit attempt to replay
the kick while the box is still unchecked. The error rises under the label on the calm spring (errors
never bounce). Checking the box clears it.
Each row is a CheckboxField. The parent is indeterminate while some columns are ticked, with its
pill sized by ratio; children it checks follow one stagger step apart (cascadeIndex).
size="sm" is a 16px box for dense lists (the default demo above). Put data-checkbox-row on a row
to show the box's halo while the row is hovered; CheckboxField sets it on its own row.
Checkbox now reads aria-invalid into its invalid state and re-emits it as aria-invalid="true"
(or nothing): aria-invalid="grammar" or "spelling" are no longer passed through.
Built on Radix Checkbox: a <button role="checkbox"> with aria-checked set to true, false or
mixed. It submits with forms when you pass name, and required uses native validation.
Give it an accessible name: a <label htmlFor> pointing at its id, or aria-label. Clicking the
label toggles the box.
The fill, tick, pill and halo are decorative (aria-hidden); the state is conveyed by
aria-checked. Announce a "select all" total in a polite live region, as the demos do.
The hit area extends to 24 by 24px (WCAG 2.5.8) without growing the box visually.
CheckboxField makes the whole row the target, at least 44px tall for touch.
CheckboxField links description and error with aria-describedby, and the error sits in a
polite live region so it is announced when it appears. Errors never rely on color alone: the
message has text and an icon.
Hover feedback has a touch equivalent: the halo also appears while pressed.
Colors come from your theme: the rim is input pulled toward foreground for 3:1 non-text
contrast, the fill is primary and the tick primary-foreground, in light and dark. A disabled
checked box keeps its tick visible.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") there is no sink,
no growth from the press point, no corner rounding and no overshoot. The primary fill and the tick
crossfade in at full size, the pill fades, and "select all" checks the children together. The
refuse kick does not move: the destructive rim and the error message carry it. The
halo and focus ring still answer, and the checked box keeps its fill, shadow and tick.
Only transform, opacity and the corner radius of an 18px box animate; one progress value drives
the circle, the corners and the glow, so React does not re-render while it moves.
Nothing loops, so there is nothing to pause off-screen or in a hidden tab. The tick of a box that
starts checked can draw once on mount with appear.
Nothing is lazy-loaded. Peers: motion and @radix-ui/react-checkbox.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 6.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-checkbox, motion.
Dependencies
@radix-ui/react-checkbox · peer
motion · peer
Triggers
toggle, press
Reduced motion
The primary fill and the tick crossfade in at full size with square corners: no sink, no growth from the press point, no overshoot, no refuse kick (the destructive rim stays), and select-all checks the children together.
Keyboard
Space
Toggles the checkbox (the box sinks while the key is down); indeterminate becomes checked
Tab
Moves focus to and from the checkbox
Enter
Does nothing on the checkbox (WAI-ARIA); submits the form natively
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)