<!-- generated by scripts/gen-docs.mjs from docs/system/checkbox.md. Edit the source and rerun. -->
# Checkbox

## Description
One choice that is on or off, or stands for a set that is partly on, and takes effect when the form is saved.

`import { Checkbox } from "@/components/cobalt/ui/checkbox"`, source `registry/cobalt/ui/checkbox.tsx`, status `ready-with-gaps`.
Foundation: `shadcn checkbox (base-luma, base)`. Traps checked: `trap/toggle-switch-submit` (Usage, `rule/checkbox-applies-on-save`), `trap/toggle-indeterminate` (Usage, `rule/checkbox-select-all-mixed`, and the States table), `trap/control-height` (n/a, a 16px box inside a Label row, never beside a button at control height), `trap/focus-ring-shape` (States, focus-visible: the global outline follows the 4px corner), `trap/hover-beats-focus` (State precedence: no hover style exists), `trap/disabled-still-hovers` (State precedence: disabled takes the not-allowed cursor and no colour change), `trap/weight-shift` (n/a, the box carries no text), `trap/motion-restart` (Motion: a colour transition reverses from where it is), `trap/motion-layout-property` (Motion: background-color and border-color only), `trap/reduced-motion-ignored` (Motion: colour changes are kept, nothing moves), `trap/tabs-routes`, `trap/current-unmarked`, `trap/list-dead-gap` and `trap/narrow-hidden-nav` (n/a, Navigation traps for a control that neither navigates nor lists).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Checkbox.Root`, a focusable `<span role="checkbox">` with `aria-checked` true, false or mixed, a hidden `<input type="checkbox">` that carries `name` and `value` to the form, `indeterminate`, `readOnly`, `required`, and Field wiring; `Checkbox.Indicator` for the glyph | `rounded-xs` (`--r-xs`, 4px); at rest the box is transparent with a 1px `--control-edge` border and no grey fill, and it takes the accent fill with the border in the same colour when checked or mixed; the `MinusIcon` for mixed beside the `CheckIcon`; the invalid hairline in `--destructive`, replaced by the accent when checked; `touch-target` for a 46px hit area under a coarse pointer; the fill and border transition on `duration-fade`; the click stops at the box so a clickable row does not also fire; no focus ring of its own, the global outline in `base.css` draws it The invalid edge is `--destructive` at full strength in the dark too; the half-strength edge was fainter than the plain unchecked edge (`docs/research/2026-10-16-break-ui-inputs.md`). |

## Examples
A set of choices under one legend, each box inside its label, sent when the form is saved.

Real uses, 0 call sites (`rg -n "<Checkbox\b" app registry docs/system/examples --glob '!registry/cobalt/ui/*' --glob '!docs/system/examples/**'`): the showcase chrome renders no Checkbox of its own, and the examples folder does not count.

Uses in other components' examples, which show the pairing the rules below rest on:
- The filter sheet, one checkbox per filter inside a Label, `docs/system/examples/sheet/default.tsx:45-46`.
- The Field page's plain Label, a box beside its words, `docs/system/examples/field/label.tsx:15-17`.

Uses inside the registry: DataTable's selection column, a box per row named after the row and the header box mixed while some are selected (`registry/cobalt/ui/data-table.tsx`).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/checkbox/default.tsx` | default | A set of choices under one legend, each box inside its label, sent when the form is saved |
| Not applicable: two boxes in default.tsx start checked | state:checked | The accent fill with a check |
| `docs/system/examples/checkbox/state-indeterminate.tsx` | state:indeterminate | Mixed while some rows are checked; it selects or clears all |
| `docs/system/examples/checkbox/state-disabled.tsx` | state:disabled | Off and on at half opacity, the label faded too, each saying why it cannot change |
| `docs/system/examples/checkbox/state-invalid.tsx` | state:invalid | A red edge on the box and the error under it, as after a submit without it, until the box is ticked |
| Not applicable: hover changes nothing on a checkbox, the cursor stays the default | state:hover | Nothing to show |
| Not applicable: focus-visible is reached with the keyboard on any example | state:focus-visible | The 2px outline 2px outside the 4px corner |
| Not applicable: read-only looks like the rest state and is reached with `readOnly` | state:read-only | `aria-readonly` and no change on press |
| `docs/system/examples/checkbox/in-label.tsx` | composition:Label | The whole row toggles the box, and the ticked columns go into the file when it is downloaded |

Example: A set of choices under one legend, each box inside its label, sent when the form is saved (`docs/system/examples/checkbox/default.tsx`)

```tsx
import { Checkbox } from "@/components/cobalt/ui/checkbox";
import { Label } from "@/components/cobalt/ui/label";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

export default function Example() {
  const save = useAction(request);
  return (
    <form
      className="flex w-full max-w-sm flex-col gap-4"
      onSubmit={(event) => {
        event.preventDefault();
        void save.run();
      }}
    >
      <fieldset className="flex flex-col gap-3">
        <legend className="mb-3 text-sm font-medium">Email me when</legend>
        <Label>
          <Checkbox name="alerts" value="filing" defaultChecked />
          A fund I follow files
        </Label>
        <Label>
          <Checkbox name="alerts" value="adviser" />
          An adviser I follow changes
        </Label>
        <Label>
          <Checkbox name="alerts" value="digest" defaultChecked />
          The weekly digest is ready
        </Label>
      </fieldset>
      {/* The button sits under the choices it saves; a failure's reason follows it on the same row.
          The row is top-aligned and the reason centred on its own, so a reason that wraps to two
          lines grows the row downward and the button never moves. */}
      <div className="flex items-start gap-3">
        <StateButton
          type="submit"
          status={save.status}
          pendingLabel="Saving"
          successLabel="Saved"
          failureLabel="Not saved"
        >
          Save changes
        </StateButton>
        <p className="min-w-0 self-center text-sm text-destructive">
          {save.error !== null ? "Check your connection and try again." : ""}
        </p>
      </div>
    </form>
  );
}
```

Example: The whole row toggles the box, and the ticked columns go into the file when it is downloaded (`docs/system/examples/checkbox/in-label.tsx`)

```tsx
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { Checkbox } from "@/components/cobalt/ui/checkbox";
import { Label } from "@/components/cobalt/ui/label";

const columns = ["Fund", "Adviser", "Domicile", "Gross assets"] as const;

const funds = [
  { Fund: "Northgate Credit", Adviser: "Northgate Capital", Domicile: "Cayman Islands", "Gross assets": "$4.8B" },
  { Fund: "Elm Street Value", Adviser: "Elm Street Partners", Domicile: "Delaware", "Gross assets": "$1.2B" },
];

// The file is made on the device from the rows on the page, so it downloads at once.
function download(chosen: readonly string[]) {
  const rows = funds.map((fund) => chosen.map((column) => `"${fund[column as keyof typeof fund]}"`).join(","));
  const url = URL.createObjectURL(new Blob([[chosen.join(","), ...rows].join("\n")], { type: "text/csv" }));
  const link = document.createElement("a");
  link.href = url;
  link.download = "funds.csv";
  link.click();
  URL.revokeObjectURL(url);
}

export default function Example() {
  const [chosen, setChosen] = useState<string[]>(["Fund", "Gross assets"]);
  return (
    <form
      className="flex w-full max-w-sm flex-col gap-4"
      onSubmit={(event) => {
        event.preventDefault();
        download(columns.filter((column) => chosen.includes(column)));
      }}
    >
      <fieldset className="flex flex-col gap-3">
        <legend className="mb-3 text-sm font-medium">Columns in the file</legend>
        {columns.map((column) => (
          <Label key={column}>
            <Checkbox
              name="columns"
              value={column}
              checked={chosen.includes(column)}
              onCheckedChange={(on) =>
                setChosen((was) => (on ? [...was, column] : was.filter((item) => item !== column)))
              }
            />
            {column}
          </Label>
        ))}
      </fieldset>
      <Button type="submit" variant="secondary" className="self-start">
        Download CSV
      </Button>
    </form>
  );
}
```

## Variants
Not applicable: Checkbox has no variant axis. `indeterminate` is a state, not a look, and the box has one size, 16px.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| unchecked | render, or `checked={false}` | press, focus | the empty box drawn by its 1px `--control-edge` border, `aria-checked="false"` | test |
| checked | press, `defaultChecked` or `checked` | press to uncheck | the check glyph, `aria-checked="true"`, `data-checked` | test |
| indeterminate | `indeterminate` while some of the set is checked | press, which the host turns into all on or all off | the minus glyph, `aria-checked="mixed"`, `data-indeterminate` | test |
| hover | pointer over | press | nothing; the box has no hover style and the cursor stays the default | by hand |
| focus-visible | keyboard focus | press with Space | the 2px outline 2px outside the corner, from `base.css` | by hand |
| disabled | `disabled` | nothing; the box leaves the tab order | half opacity from `data-disabled` (Base UI draws a `span`, which `:disabled` never matches; measured 1 before the fix, 0.5 after, Playwright 2026-10-17), the not-allowed cursor, `aria-disabled="true"`; inside a Label the whole row fades to half once, the box included, and the box does not fade again | test |
| invalid | `aria-invalid` from `Field` or the host | press | the `--destructive` hairline, which the accent replaces once checked | test |
| read-only | `readOnly` | focus, read | `aria-readonly="true"`; a press changes nothing | by hand |

Example: Mixed while some rows are checked; it selects or clears all (`docs/system/examples/checkbox/state-indeterminate.tsx`)

```tsx
import { useState } from "react";

import { Checkbox } from "@/components/cobalt/ui/checkbox";
import { Label } from "@/components/cobalt/ui/label";

const lists = ["Mentors", "Alumni", "Volunteers"];

const sizes: Record<string, number> = { Mentors: 14, Alumni: 212, Volunteers: 37 };

export default function Example() {
  const [chosen, setChosen] = useState<string[]>(["Mentors"]);
  const all = chosen.length === lists.length;
  const some = chosen.length > 0 && !all;
  const people = chosen.reduce((sum, list) => sum + (sizes[list] ?? 0), 0);
  return (
    <div className="flex flex-col gap-3">
      <Label>
        <Checkbox
          checked={all}
          indeterminate={some}
          onCheckedChange={(on) => setChosen(on ? [...lists] : [])}
        />
        All lists
      </Label>
      <div className="flex flex-col gap-3 pl-6">
        {lists.map((list) => (
          <Label key={list}>
            <Checkbox
              checked={chosen.includes(list)}
              onCheckedChange={(on) =>
                setChosen((was) => (on ? [...was, list] : was.filter((item) => item !== list)))
              }
            />
            {list}
          </Label>
        ))}
      </div>
      <p className="text-sm text-muted-foreground tabular-nums">Sends to {people} people.</p>
    </div>
  );
}
```

Example: Off and on at half opacity, the label faded too, each saying why it cannot change (`docs/system/examples/checkbox/state-disabled.tsx`)

```tsx
import { Checkbox } from "@/components/cobalt/ui/checkbox";
import { Label } from "@/components/cobalt/ui/label";

export default function Example() {
  return (
    <div className="flex flex-col gap-3">
      <Label>
        <Checkbox disabled />
        <span className="flex min-w-0 flex-col gap-0.5">
          Two factor sign in
          <span className="font-normal text-muted-foreground">Managed by your organisation</span>
        </span>
      </Label>
      <Label>
        <Checkbox disabled defaultChecked />
        <span className="flex min-w-0 flex-col gap-0.5">
          Single sign on
          <span className="font-normal text-muted-foreground">Managed by your organisation</span>
        </span>
      </Label>
    </div>
  );
}
```

Example: A red edge on the box and the error under it, as after a submit without it, until the box is ticked (`docs/system/examples/checkbox/state-invalid.tsx`)

```tsx
import { useState } from "react";

import { Checkbox } from "@/components/cobalt/ui/checkbox";
import { Field, FieldError, FieldLabel } from "@/components/cobalt/ui/field";

export default function Example() {
  const [agreed, setAgreed] = useState(false);
  return (
    <Field>
      <FieldLabel>
        <Checkbox checked={agreed} onCheckedChange={setAgreed} />I agree to the cancellation policy
      </FieldLabel>
      <FieldError reserve>{agreed ? "" : "Agree to the cancellation policy to book the room."}</FieldError>
    </Field>
  );
}
```

### State precedence
- Disabled and hover: disabled wins. There is no hover style, and the cursor is not-allowed.
- Disabled and focus-visible: disabled wins. The box leaves the tab order, so no outline shows.
- Disabled and checked: both show. The glyph stays on the faded box so the value is still readable.
- Hover and focus-visible: focus-visible wins. Hover draws nothing, so the outline is the only change.
- Invalid and checked: checked wins. The hairline turns to the accent, since a checked box answers the error.
- Invalid and disabled: disabled wins. A disabled control inside an invalid form shows no error of its own.
- Indeterminate and checked: indeterminate wins. Base UI reports `mixed` whatever `checked` holds.
- Read-only and focus-visible: both show. The box takes focus and the outline, and a press changes nothing.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| unchecked to checked or mixed, and back | announce | `duration-fade` (`--t-fade`, 150ms) on `--curve` | background-color, border-color | the same colour change; `base.css` keeps colour transitions and the glyph never moves |
| pointer over and out | announce | none | nothing changes | nothing |

## Props

<!-- Props generated from registry/cobalt/ui/checkbox.tsx with TypeScript by scripts/props-table.mjs -->
No props of its own.

Also accepts every native `<span>` attribute; from Base UI: `checked`, `defaultChecked`, `disabled`, `form`, `id`, `indeterminate`, `inputRef`, `name`, `nativeButton`, `onCheckedChange`, `parent`, `readOnly`, `render`, `required`, `uncheckedValue`, `value`.

Every Base UI `Checkbox.Root` prop passes through: `checked`, `defaultChecked`, `onCheckedChange`, `indeterminate` (defaults to false), `disabled`, `readOnly`, `required`, `name`, `value`, `inputRef`, `aria-*`. `className` is merged last and is for placement. `onClick` still fires after the box stops the event, so a row that holds the box does not also toggle.

## Usage

### When to use
- You turn one option on or off and the change applies when the form is saved.
- You pick any number of items from a list: filters, lists to send to, rows to act on.
- One box stands for a set of rows and must say "some" as well as "all" and "none".

### When not to use
- The setting applies the moment it flips. Use Switch instead.
- Exactly one of a few options may be chosen. Use SegmentedControl instead, or Select past 4 options.
- The on state is a filter chip in a row of chips. Use Pill instead.
- A list of rows a person selects to act on together. Use DataTable instead, with `selection` and `DataTableToolbar`.

### Rules
- `rule/checkbox-in-label`: When a checkbox has a word beside it, put the box and the word inside one `Label` instead of a `div` with text, because the word becomes the accessible name and the whole row becomes the hit area. Evidence: app 5/5 example uses outside this folder wrap the box in a Label or a FieldLabel, such as `docs/system/examples/sheet/default.tsx:45-46` and `docs/system/examples/field/label.tsx:15-16`; principle wcag: 4.1.2 Name, role, value, a checkbox with no name is announced as "checkbox" alone. Check: lint trap/label-unbound (scripts/check-system.mjs); review.
  - Don't: `<div className="flex gap-2"><Checkbox /> Email me about replies</div>`
  - Do: `<Label><Checkbox /> Email me about replies</Label>`
- `rule/checkbox-select-all-mixed`: When one checkbox stands for a set of rows, pass `indeterminate` while some of them are checked, and make its press check every row when any is off and uncheck every row when all are on, because a select-all with two states says "none" while some are on. Evidence: principle platform: the native checkbox's indeterminate state, exposed as `aria-checked="mixed"`, exists for this one case. Check: test `checkbox.test.tsx` renders `indeterminate` as `aria-checked="mixed"`; review of every select-all.
  - Don't: `<Checkbox checked={chosen.length === rows.length} onCheckedChange={(on) => setChosen(on ? rows : [])} />`
  - Do: `<Checkbox checked={all} indeterminate={some} onCheckedChange={(on) => setChosen(on ? rows : [])} />`
- `rule/checkbox-applies-on-save`: When the choice takes effect only when the form is saved, use Checkbox, and when it takes effect at once use Switch instead, because a switch promises a change on the flip and a checkbox promises one on submit. Evidence: principle platform: the switch role is an immediate on and off (the WAI-ARIA switch pattern, the iOS switch), and the native checkbox is a form value. Check: review of every Switch inside a form with a submit button.
  - Don't: `<form><Label><Switch name="newsletter" /> Weekly digest</Label><Button type="submit">Save</Button></form>`
  - Do: `<form><Label><Checkbox name="newsletter" /> Weekly digest</Label><Button type="submit">Save</Button></form>`
- `rule/checkbox-value-through-name`: When the box belongs to a form that submits, give it `name` and, for a set, `value`, instead of mirroring it into state only for the submit handler to read, because the hidden `<input type="checkbox">` already carries the value and the browser's form data. Evidence: principle platform: the native checkbox submits `name=value` when checked and nothing when not, and the hidden input in the markup carries both. Check: test `checkbox.test.tsx` "carries its value to the form"; review.
  - Don't: `<Checkbox checked={upcoming} onCheckedChange={setUpcoming} />` with `onSubmit={() => post({ upcoming })}`
  - Do: `<Checkbox name="filters" value="upcoming" />`
- `rule/checkbox-row-click-once`: When a checkbox sits in a row that itself opens on click, leave the row's `onClick` alone and let the box stop its own click, instead of toggling the box from the row handler as well, because one press would then toggle twice. Evidence: principle input: pointer, one press reaches one handler, and the box calls `stopPropagation` before the host's `onClick`. Check: review of every row that holds a Checkbox.
  - Don't: `<tr onClick={() => { open(row); toggle(row) }}><td><Checkbox checked={isOn(row)} /></td></tr>`
  - Do: `<tr onClick={() => open(row)}><td><Checkbox checked={isOn(row)} onCheckedChange={() => toggle(row)} /></td></tr>`

### Content
- Follows `rule/writing-field-label-noun`.
- `rule/checkbox-label-says-the-on-case`: When the label is written, it says what being checked means, as a positive statement in sentence case such as "Email me about replies", instead of a negative such as "Don't email me", because a checked negative is a double negative read at a glance. Evidence: person D11; principle heuristic: match between system and the real world, the label states the outcome of checking. Check: lint copy/casing on the field-label slot (scripts/copy-check.mjs); review.
  - Don't: `<Label><Checkbox /> Don't email me about replies</Label>`
  - Do: `<Label><Checkbox /> Email me about replies</Label>`

### Anti-slop
- `rule/checkbox-no-native-input`: When an agent reaches for `<input type="checkbox">` with classes on it, use `Checkbox` instead, because the native box ignores the tokens, draws the browser's glyph and has no mixed glyph. Evidence: app 2/2 example uses outside this folder use Checkbox and 0 render a native checkbox (`rg -n 'type="checkbox"' app docs/system/examples`); person D13. Check: review, `rg -n 'type="checkbox"' app docs/system/examples` returns no line.
  - Don't: `<input type="checkbox" className="size-4 accent-primary" />`
  - Do: `<Checkbox />`
- `rule/checkbox-keep-the-box-size`: When a design wants a bigger box, keep the 16px box and let the Label's row be the target, instead of passing `className="size-6"`, because the glyph is 14px and the hit area is already 46px under a coarse pointer. Evidence: measured a 46 by 46 hit area at 390 under a coarse pointer, .design-system/evidence/checkbox/colors-390.json; principle wcag: 2.5.8 Target size (minimum), 24px. Check: lint rule/component-override on Checkbox (scripts/check-system.mjs).
  - Don't: `<Checkbox className="size-6 rounded-md" />`
  - Do: `<Label className="py-2"><Checkbox /> Show my profile in search</Label>`

### Limits
- Not applicable: the box is fixed at 16px and the label wraps inside the Label row, so no count, length or width breaks it; there is nothing to grow and measure.

## Accessibility
Rests on Base UI `Checkbox.Root`: a focusable `<span role="checkbox">` with a hidden native `<input type="checkbox">` beside it for the form.

Contrast, as drawn (.design-system/evidence/checkbox/colors-390.json): the check glyph on the accent fill 6.07:1 light and 7.53:1 dark; the accent fill against the page 5.66:1 light and 7.91:1 dark; the unchecked box is drawn by its 1px `--control-edge` border, which the token states as 3:1 against the page (WCAG 1.4.11 Non-text contrast); the earlier 1.18:1 and 1.4:1 readings were of the grey fill that is gone, and the edge itself has not been re-measured. NEEDS REVIEW.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the box | focuses it and shows the outline | the box | by hand |
| Space | the box | toggles it; a mixed box becomes whatever the host sets | the box | by hand |
| Enter | the box | nothing, as on a native checkbox; Base UI blocks the button behaviour | the box | by hand |
| Tab | a disabled box | skips it | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | checkbox | the wrapping `Label` or `FieldLabel` (inside a `Field`, `aria-labelledby` to it and `aria-describedby` to the description and error, set by Base UI), or `aria-label` or `aria-labelledby` from the host | `aria-checked` true, false or mixed, `aria-disabled`, `aria-readonly`, `aria-required`, `aria-invalid` from Field | the name, "checkbox", and checked, not checked or mixed; the change on each press | test |
| hidden input | none | none, `aria-hidden` | `name`, `value`, `checked`, `disabled` for the form | nothing | test |

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--r-xs`, `--t-fade`, `--curve`, `--touch`, `--ring`, `--line-focus`, `--focus-offset` |
| root | unchecked | `--control-edge` as the 1px border, no fill |
| root | checked, indeterminate | `--primary`, `--primary-foreground` |
| root | invalid | `--destructive`, at 50 percent in the dark |

## Related
- Switch: a setting that applies at once.
- SegmentedControl: exactly one of a few options.
- Pill: a filter that is on or off in a row of chips.
- Field: the Label that wraps the box with its word, and the label, description and error around a required box.
- DataTable: lists records with the same fields, as many as a server holds.
- Select: picks one of up to 10 known options from a list that opens on demand.
- Toggle: keeps a tool pressed or not, such as bold in a toolbar or "Show archived" beside a list.
- RadioGroup: exactly one choice among a few, all in view.
