Checkbox

An animated checkbox built on Base UI that draws its tick with a stroke, bends the same path into a dash when mixed (indeterminate), and squashes slightly on press. It can render bare or with a label and description, and CheckboxGroup coordinates a parent select-all checkbox.

Checkbox
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @stealth/checkbox

Requires @stealth in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { Checkbox } from "@/components/ui/checkbox";export function Example() {  return <Checkbox label="Send me product updates" description="About once a month." />;}
  • Forms and settings where users toggle a boolean option, optionally with a label and helper description
  • Lists where a parent checkbox should show select-all, none, or mixed state via CheckboxGroup
  • Compact bare checkboxes in tables or toolbars where the box alone is the touch target (grown to 44px hit area)
  • Validation flows where an invalid state should be shown after a failed submit

Examples

Controlled checkbox with label

A controlled checkbox bound to React state using Base UI's checked and onCheckedChange props.

controlled-checkbox-with-label.tsx
import { useState } from "react";import { Checkbox } from "@/components/ui/checkbox";export function NotificationsToggle() {  const [checked, setChecked] = useState(false);  return (    <Checkbox      label="Email notifications"      description="Receive a summary every morning."      checked={checked}      onCheckedChange={setChecked}    />  );}

Select-all with CheckboxGroup

A parent checkbox that becomes mixed when only some children are selected, using CheckboxGroup with allValues and a controlled value.

select-all-with-checkboxgroup.tsx
import { useState } from "react";import { Checkbox, CheckboxGroup } from "@/components/ui/checkbox";const fruits = ["apple", "banana", "cherry"];export function FruitPicker() {  const [value, setValue] = useState<string[]>([]);  return (    <CheckboxGroup value={value} onValueChange={setValue} allValues={fruits}>      <Checkbox parent label="All fruits" />      {fruits.map((f) => (        <Checkbox key={f} value={f} label={f} />      ))}    </CheckboxGroup>  );}

Invalid state after failed submit

Marks the box as invalid with the invalid prop and a required native constraint.

invalid-state-after-failed-submit.tsx
import { Checkbox } from "@/components/ui/checkbox";export function TermsField({ showError }: { showError: boolean }) {  return (    <Checkbox      label="I accept the terms"      required      invalid={showError}    />  );}

API reference

PropTypeDefaultDescription
labelReact.ReactNode—Visible label. The whole label is the hit target. When provided the component renders a wrapping label element.
descriptionReact.ReactNode—A quieter line under the label, linked to the checkbox via aria-describedby.
size"sm" | "md""md"Visual size. sm uses a 14px box and smaller text; md uses a 16px box.
invalidbooleanfalseMarks the box as invalid, applying danger styling and aria-invalid. Set it after a failed submit, not while the person is still deciding.
classNamestring—Applied to the outermost element: the label when there is one, otherwise the box.
aria-describedbystring—Extra description IDs, merged with the internal description ID when description is set.
...restOmit<BaseCheckbox.Root.Props, "className" | "children">—All other Base UI Checkbox.Root props such as checked, defaultChecked, onCheckedChange, indeterminate, disabled, readOnly, required, name, value, and parent. children is not accepted.
CheckboxGroup.classNamestring—Class name for the group container, merged after flex flex-col gap-2.5. CheckboxGroup also accepts all Base UI CheckboxGroup props such as value, onValueChange, and allValues.

Accessibility

  • The box is a Base UI checkbox root, so it exposes checkbox role, checked, mixed, and disabled states to assistive technology.
  • When a label is provided the checkbox is wrapped in a label element, so clicking or tapping the text toggles the box.
  • description is linked through aria-describedby using a generated ID, and any extra aria-describedby values are merged.
  • invalid sets aria-invalid to true; use it only after a failed submit so users are not flagged mid-decision.
  • The decorative SVG mark is aria-hidden and not focusable, so screen readers rely on the checkbox state rather than the drawn shape.
  • Focus-visible shows a clear outline offset from the box. Motion is disabled under prefers-reduced-motion, and the press squash only applies when motion is safe.
  • Without a label the box enlarges its clickable area to about 44px via an after pseudo-element to help touch users.
  • Use a visible label or aria-label so the checkbox has an accessible name; the bare box has no text of its own.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Checkbox" component (stealth/checkbox) from its shadcn registry.1. Install it with: npx shadcn@latest add @stealth/checkbox2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: label, description, size, invalid, className, aria-describedby, ...rest, CheckboxGroup.className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Checkbox } from "@/components/ui/checkbox";export function Example() {  return <Checkbox label="Send me product updates" description="About once a month." />;}```

Files & dependencies

  • components/ui/checkbox.tsx
dependencies@base-ui/reactmotion
registryDependencieshttps://www.stealth.pm/r/tokens.jsonhttps://www.stealth.pm/r/cn.jsonhttps://www.stealth.pm/r/motion.json

Looks similar, elsewhere