When to use
- Let people pick any number of options from a list, such as the columns to export.
- Select or clear a whole group in one click with a parent checkbox that shows a dash when only some are checked.
- Collect an opt-in that only takes effect when a form is submitted, such as "Include totals".
When not to use
- A setting that applies the moment it changes: use a Switch.
- Exactly one choice from a few: use a Radio Group or Segmented.
- Toggling formatting in a toolbar: use a Toggle Group.
Installation
pnpm dlx shadcn add https://eased.dev/r/checkbox.jsonnpx shadcn add https://eased.dev/r/checkbox.jsonyarn dlx shadcn add https://eased.dev/r/checkbox.jsonbunx --bun shadcn add https://eased.dev/r/checkbox.jsonThe command adds Checkbox, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/react motionnpm install @base-ui/react motionyarn add @base-ui/react motionbun add @base-ui/react motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/checkbox/checkbox.tsxTSX "use client";import { Checkbox as BaseCheckbox } from "@base-ui/react/checkbox";import { CheckboxGroup as BaseCheckboxGroup } from "@base-ui/react/checkbox-group";import { motion } from "motion/react";import { useId, type ReactNode } from "react";import { ease, duration, reducedFade, snappy, useSafeReducedMotion } from "../lib/motion";/* * One stroke, three points, two shapes: the check and the indeterminate dash share a command * structure, so the check's corner slides up into a straight line instead of cross-fading. */const CHECK = "M4.25 8.4 L6.9 11 L11.75 5.25";const DASH = "M4.5 8 L8 8 L11.5 8";// Colour on the standard curve; the box presses to 0.9 in 100ms and springs back (rule 63).const PRESS = "[transition:background-color_150ms_var(--eased-ease-standard),border-color_150ms_var(--eased-ease-standard),scale_var(--eased-duration-spring-snappy)_var(--eased-spring-snappy)] group-active:scale-90 group-active:duration-(--eased-duration-instant) group-active:ease-standard reduced:group-active:scale-none group-data-disabled:scale-none group-data-readonly:scale-none";/** The 16px box: the fill tints in, the mark draws on and morphs between check and dash. */function CheckboxControl({ checked, indeterminate, disabled }: { checked: boolean; indeterminate: boolean; disabled: boolean }) { const reduced = useSafeReducedMotion(); const on = checked || indeterminate; const shape = indeterminate ? DASH : CHECK; const transition = reduced ? { d: { duration: 0 }, pathLength: { duration: 0 }, opacity: reducedFade } : on ? { d: snappy, pathLength: { duration: duration.standard, ease: ease.enter }, opacity: { duration: duration.instant } } : { d: snappy, pathLength: { duration: duration.instant, ease: ease.exit }, opacity: { duration: duration.instant, delay: 0.04 } }; return ( <span aria-hidden className={`relative flex size-4 shrink-0 items-center justify-center rounded-control-2xs border ${PRESS} ${ disabled ? on ? "border-transparent bg-text-disabled" : "border-line bg-surface-sunken" : on ? "border-brand bg-brand" : "border-line-strong bg-surface group-hover-fine:border-text-muted" }`} > <svg viewBox="0 0 16 16" fill="none" className="absolute -inset-px size-4 overflow-visible"> <motion.path initial={false} animate={{ d: shape, pathLength: on ? 1 : 0, opacity: on ? 1 : 0 }} transition={transition} className={disabled ? "stroke-surface" : "stroke-text-on-brand"} strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round" /> </svg> </span> );}export type CheckboxProps = { /** Checked (controlled). */ checked?: boolean; /** Initially checked (uncontrolled). */ defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; /** Shows the dash. A parent checkbox in a `CheckboxGroup` sets this itself. */ indeterminate?: boolean; /** Controls every checkbox in its `CheckboxGroup`: checks or clears them all, and shows the dash when some are checked. */ parent?: boolean; /** Its value inside a `CheckboxGroup`, and what a form submits under `name`. */ value?: string; name?: string; disabled?: boolean; required?: boolean; readOnly?: boolean; /** The label. Clicking anywhere on the row toggles it. Leave it out for a bare box, and pass `aria-label`. */ children?: ReactNode; /** Muted text under the label, e.g. why it is disabled. */ description?: ReactNode; "aria-label"?: string; id?: string; className?: string;};/** * A checkbox on Base UI: keyboard (Space), form submission, Field validation and group * parents. The fill tints in, the check draws itself, and the indeterminate dash is the same * stroke straightened, so check ⇄ dash morphs rather than swaps. */export function Checkbox({ children, description, className = "", ...props }: CheckboxProps) { const id = useId(); const labelled = children != null; return ( <BaseCheckbox.Root {...props} aria-labelledby={labelled ? `${id}-label` : undefined} aria-describedby={description ? `${id}-desc` : undefined} render={(htmlProps, state) => ( <span {...htmlProps}> {labelled ? ( <> {/* 16px box centred on the 14px label's 20px first line (rule 107). */} <span className="flex h-5 items-center"> <CheckboxControl checked={state.checked} indeterminate={state.indeterminate} disabled={state.disabled} /> </span> <span className="flex min-w-0 flex-col gap-0.5"> <span id={`${id}-label`} className={`text-ui ${state.disabled ? "text-text-disabled" : "text-text"}`}> {children} </span> {description && ( <span id={`${id}-desc`} className="text-ui-sm text-text-muted text-pretty"> {description} </span> )} </span> </> ) : ( <CheckboxControl checked={state.checked} indeterminate={state.indeterminate} disabled={state.disabled} /> )} </span> )} className={(state) => `group inline-flex min-w-0 items-start text-left select-none focus-ring ${ labelled ? "gap-2.5 rounded-control-xs py-1.5" : "rounded-control-2xs" } ${state.disabled ? "cursor-not-allowed" : state.readOnly ? "cursor-default" : "cursor-pointer"} ${className}` } /> );}export type CheckboxGroupProps = { /** Checked values (controlled). */ value?: string[]; /** Initially checked values (uncontrolled). */ defaultValue?: string[]; onValueChange?: (value: string[]) => void; /** Every child's value. Required when the group has a `parent` checkbox. */ allValues?: string[]; disabled?: boolean; "aria-label"?: string; "aria-labelledby"?: string; className?: string; children: ReactNode;};/** A list of checkboxes that share one value array, with an optional parent "Select all". */export function CheckboxGroup({ className = "", onValueChange, children, ...props }: CheckboxGroupProps) { return ( <BaseCheckboxGroup {...props} onValueChange={(v) => onValueChange?.(v)} className={`flex flex-col ${className}`}> {children} </BaseCheckboxGroup> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Checkbox } from "@/components/eased/checkbox/checkbox";export function ExportOptions() { return ( <Checkbox name="totals" defaultChecked description="Adds a row with the total of each number column."> Include totals </Checkbox> );}Examples
Group with a parent
Wrap checkboxes in CheckboxGroup to share one value array. A parent checkbox checks or clears them all and shows the dash when some are checked; pass every child's value as allValues.
const columns = ["invoice", "customer", "amount", "status"];const [value, setValue] = useState(["invoice", "amount"]);<CheckboxGroup aria-label="Columns" value={value} onValueChange={setValue} allValues={columns}> <Checkbox parent>All columns</Checkbox> <Checkbox value="invoice">Invoice number</Checkbox> <Checkbox value="customer">Customer</Checkbox> <Checkbox value="amount">Amount</Checkbox> <Checkbox value="status">Status</Checkbox></CheckboxGroup>Disabled, with the reason
Say why an option is unavailable in description, so people know what would unlock it.
<Checkbox disabled description="Available on the Business plan."> Schedule a weekly export</Checkbox>Bare box
Leave out children in a table row or another layout that already shows the label, and name it with aria-label.
<Checkbox aria-label="Select invoice INV-2041" checked={selected} onCheckedChange={setSelected} />API reference
Checkbox
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | Checked (controlled). | |
defaultChecked | boolean | Initially checked (uncontrolled). | |
onCheckedChange | (checked: boolean) => void | ||
indeterminate | boolean | Shows the dash. A parent checkbox sets this itself. | |
parent | boolean | Controls every checkbox in its CheckboxGroup. | |
value | string | Its value inside a CheckboxGroup, and what a form submits under name. | |
name | string | Form field name. | |
disabled | boolean | ||
required | boolean | ||
readOnly | boolean | Shows the state but doesn't change on click. | |
children | ReactNode | The label. Clicking anywhere on the row toggles it. | |
description | ReactNode | Muted text under the label. | |
aria-label | string | Names a bare box with no children. | |
id | string | ||
className | string | "" | Appended to the root's classes. |
CheckboxGroup
| Prop | Type | Default | Description |
|---|---|---|---|
value | string[] | Checked values (controlled). | |
defaultValue | string[] | Initially checked values (uncontrolled). | |
onValueChange | (value: string[]) => void | ||
allValues | string[] | Every child's value. Required with a parent checkbox. | |
disabled | boolean | Disables every checkbox in the group. | |
aria-label | string | Names the group. | |
aria-labelledby | string | Names the group from a visible heading. | |
className | string | "" | Appended to the group's classes. It stacks its children in a column. |
Keyboard
| Key | Action |
|---|---|
Tab | Moves focus to the checkbox. Each checkbox in a group is its own tab stop. |
Space | Toggles it. On a parent, checks or clears the whole group. |
Accessibility
- The root has
role="checkbox"andaria-checked, which reads "mixed" when indeterminate. A hidden input submits it with forms and works with Field validation. - With
children, the label names the checkbox througharia-labelledby, anddescriptiondescribes it througharia-describedby. Withoutchildren, passaria-label. - The focus ring draws around the whole row, label included.
- A labelled row is 32px tall and toggles anywhere you press. A bare box is 16px, so give it a larger row or cell to press in on touch screens.
Motion
The fill and border tint in over 150ms on the standard curve. The check draws itself in 200ms on the enter curve and retracts in 100ms on the exit curve as it fades. The indeterminate dash is the same stroke straightened, so check and dash morph into each other on the snappy spring instead of cross-fading. The box presses to 0.9 in 100ms and springs back on the snappy spring; disabled and read-only boxes don't press. Reduced motion: the mark appears and disappears with a 100ms fade, and the box doesn't press.
Notes for AI
Pick Checkbox for options that take effect on submit and for multi-select lists; pick Switch when the change applies at once. For a "Select all", use CheckboxGroup with a parent checkbox and allValues; don't compute the indeterminate state yourself.
Don't wrap it in a <label> or put a Label next to it: pass the label as children and the helper text as description, and the row handles naming and the click target. Don't animate the check yourself.
Responsive
A long label wraps under itself, and the box stays on the label's first line. Descriptions wrap with text-pretty.
Related components
- Animated Switch: a setting that applies the moment it flips.
- Radio Group and Radio Cards: exactly one choice from a list.
- Form Field with Validation: adds validation messages around a control.