<!-- index: /slotted/llms.txt -->
# checkbox

`data-ui="checkbox"` · Box that turns one option on or off.

## Import

```tsx
import { Checkbox, CheckboxDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Checkbox } from '@slotted/react/checkbox';
import { Stack } from '@slotted/react/stack';

export default function CheckboxBasic() {
  return (
    <Stack gap={3}>
      <Checkbox defaultChecked>Email the invoice to the customer</Checkbox>
      <Checkbox defaultChecked>Include a packing slip</Checkbox>
      <Checkbox>Gift-wrap the order</Checkbox>
    </Stack>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, or the element render returns | yes |
| `control` | input type="checkbox" | yes |
| `indicator` | span | yes |
| `label` | label | no |
| `description` | p | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `checked` | `boolean` | — | Checkbox | Makes the state controlled for the life of the component. Without it the input keeps its own state, and a native form reset restores defaultChecked. Inside a checkbox group, the group’s selection decides instead. |
| `defaultChecked` | `boolean` | false | Checkbox | The state an uncontrolled box starts from. It is read once and written to the input as the native attribute, which is what a form reset returns to. |
| `indeterminate` | `boolean` | false | Checkbox | The mixed state, drawn as a dash and announced as mixed. It is a state, not a third value of checked: the submitted value stays boolean, because indeterminate is a DOM property that leaves checked unchanged. |
| `parent` | `boolean` | false | Checkbox | Makes the box command the set its checkbox group lists in allValues. It is checked when every value is selected and mixed when some are, and a press selects or clears the whole set. Outside a group with allValues it has no effect. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Checkbox, CheckboxDefaultsProvider | The step of the control scale. When unset, the box takes the size of its checkbox group, then of its field or field group, then of the provider. The theme restates the scale per density. |
| `variant` | `'plain' \| 'tile' \| 'control'` | plain | Checkbox, CheckboxDefaultsProvider | How the choice is drawn. tile frames it and makes the whole surface the target; the label still names the control, so the keyboard and the accessible name are unchanged. control is for a row of fields and buttons: the root is one control tall and holds the hover halo inside its own box, where the plain halo stands outside the root and is shorter than a control. When unset, the box takes the variant of its checkbox group, then of the provider. |
| `labelPlacement` | `'end' \| 'start'` | end | Checkbox, CheckboxDefaultsProvider | Which side of its label the box sits on. When unset, the box takes the placement of its checkbox group, then of the provider. It is never read from a field, whose labelPlacement places the field’s own label. |
| `disabled` | `boolean` | from the group or field, or false | Checkbox | Unset rather than false, so the box follows its checkbox group or field. Written as the native attribute, which removes the box from the tab order and from form submission. |
| `readOnly` | `boolean` | from the group or field, or false | Checkbox | Unset rather than false. A native checkbox has no readonly, so Checkbox refuses every change and writes aria-readonly. The box keeps its tab stop, its focus ring and its contrast, and its value is still submitted. |
| `invalid` | `boolean` | from the group or field, or false | Checkbox | Unset rather than false. Writes aria-invalid on the input and data-invalid on the root, which draws a thicker border in the danger tone. |
| `required` | `boolean` | — | Checkbox | The native attribute, passed through unchanged; Checkbox never writes it. A field marks necessity with aria-required instead, because the native attribute turns on browser constraint validation. |
| `description` | `ReactNode` | — | Checkbox | Help text under the label, referenced by aria-describedby. It sits outside the label, so it describes the control instead of naming it. |
| `name / value` | `string` | — / on | Checkbox | The native submission pair: a checked box submits value under name. Inside a checkbox group, a box without a name takes the group’s, and value is the entry the group’s selection holds. |
| `render` | `(props: CheckboxRootProps) => ReactNode` | — | Checkbox | Replaces the root element and receives every attribute it would carry. The props are typed against HTMLAttributes<HTMLElement>, so they can be spread onto a li or a label. The input cannot be replaced, because it holds the value and the platform’s keyboard behavior. |
| `ref` | `Ref<HTMLInputElement>` | — | Checkbox | Reaches the input. focus() and click() are the element’s own methods. |
| `className / style` | `string / CSSProperties` | — | Checkbox | Reach the root. Every other native prop reaches the input. |
| `CheckboxDefaultsProvider` | `{ size, variant, labelPlacement }` | — | a subtree | Sets size, variant and labelPlacement once for every box under it, merged over an outer provider. A box that states a value keeps it. A checkbox group around the box outranks the provider for all three, and a field or field group outranks it for size. |
| `useField()` | `() => FieldContextValue \| undefined` | — | inside a Field | What the box reads from a field: its disabled, readOnly, invalid and required states, its description and error, and its size. The box never takes the field’s identifier: it has its own label, and the field’s label would name the same control twice. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onCheckedChange` | `(checked: boolean, request: ChangeRequest<boolean>)` | Before the box moves. request.value is the new state and request.previous the state it replaces. request.reason is pointer or keyboard, read from the click’s detail, and request.source is the originating event. request.cancel() refuses the change before anything commits, including the platform’s own toggle. |
| `onChange, onClick, onFocus, onBlur` | `the element’s own events` | Whenever the input fires them. Checkbox composes your handler with its own instead of replacing it: yours runs first, and always runs. Calling preventDefault() in onClick stops the change as well. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `plain`, `tile`, `control` | `plain` |
| `labelPlacement` | `end`, `start` | `end` |

## Rules

- Checkbox follows the WAI-ARIA Authoring Practices checkbox pattern (w3.org/WAI/ARIA/apg/patterns/checkbox/), and the native input supplies every part of it: the role, the checked and mixed states, Space to toggle, Enter left to the form, and disabled behavior. Checkbox adds no key listener, so the keyboard behavior is the platform’s in every language and in right-to-left documents.
- The label names the control through for, which points at an identifier Checkbox generates when you pass no id. The description sits outside the label and reaches the control through aria-describedby, so it is read as a description, and a press on it toggles nothing.
- Inside a required field the control carries aria-required, never the native required, because the native attribute turns on browser constraint validation and changes how the form submits. Pass required on the box to opt into the platform’s validation; Checkbox leaves it unchanged. disabled is the native attribute.
- A native checkbox has no read-only state, so Checkbox enforces one: it refuses the click that a pointer and Space both produce, and aria-readonly announces the state. The box keeps its tab stop, its focus ring and its full contrast, because a read-only value is real and must not look disabled.
- The invalid state does not rely on color alone. In the high-contrast scheme the theme paints every border the same color, so an invalid box also draws a thicker border. The message that says what is wrong belongs to the field or field group.
- The target is larger than the box. A 24-pixel square around the box meets WCAG 2.2 success criterion 2.5.8 at every size and density, including size="sm", where the box is 14 pixels. The label extends the target to the end of its text, and the hover wash covers exactly that area. The target is drawn around the box, so the row keeps its line height.
- The mark stays visible under forced colors. It is a mask over a background color, and forced colors replace both, so Checkbox restates the pair in system colors.

## Tokens

`--slotted-border-strong`, `--slotted-border-width-medium`, `--slotted-border-width-thick`, `--slotted-checkbox-active-background`, `--slotted-checkbox-background`, `--slotted-checkbox-border-color`, `--slotted-checkbox-border-width`, `--slotted-checkbox-checked-active-background`, `--slotted-checkbox-checked-background`, `--slotted-checkbox-checked-border-color`, `--slotted-checkbox-checked-hover-background`, `--slotted-checkbox-color`, `--slotted-checkbox-description-color`, `--slotted-checkbox-description-font-size`, `--slotted-checkbox-disabled-background`, `--slotted-checkbox-disabled-border-color`, `--slotted-checkbox-disabled-color`, `--slotted-checkbox-disabled-mark-color`, `--slotted-checkbox-halo-color`, `--slotted-checkbox-hover-border-color`, `--slotted-checkbox-invalid-border-color`, `--slotted-checkbox-invalid-checked-background`, `--slotted-checkbox-invalid-edge-width`, `--slotted-checkbox-invalid-focus-ring-color`, `--slotted-checkbox-line-height`, `--slotted-checkbox-mark-color`, `--slotted-checkbox-mark-inset`, `--slotted-checkbox-radius`, `--slotted-checkbox-readonly-background`, `--slotted-checkbox-size`, `--slotted-checkbox-tile-active-background`, `--slotted-checkbox-tile-background`, `--slotted-checkbox-tile-border-color`, `--slotted-checkbox-tile-checked-background`, `--slotted-checkbox-tile-checked-border-color`, `--slotted-checkbox-tile-checked-hover-border-color`, `--slotted-checkbox-tile-description-gap`, `--slotted-checkbox-tile-disabled-background`, `--slotted-checkbox-tile-disabled-border-color`, `--slotted-checkbox-tile-hover-background`, `--slotted-checkbox-tile-hover-border-color`, `--slotted-checkbox-tile-inset`, `--slotted-checkbox-tile-invalid-border-color`, `--slotted-checkbox-tile-invalid-checked-background`, `--slotted-checkbox-tile-invalid-checked-border-color`, `--slotted-checkbox-tile-radius`, `--slotted-checkbox-tile-readonly-background`, `--slotted-checkbox-tile-readonly-border-color`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-invalid-edge-width`, `--slotted-control-label-gap-lg`, `--slotted-control-label-gap-md`, `--slotted-control-label-gap-sm`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-duration-medium`, `--slotted-focus-ring-color`, `--slotted-focus-ring-color-invalid`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-size-xs`, `--slotted-line-height-md`, `--slotted-line-height-xs`, `--slotted-radius-md`, `--slotted-radius-xs`, `--slotted-selection-halo-opacity`, `--slotted-selection-size-lg`, `--slotted-selection-size-md`, `--slotted-selection-size-sm`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-surface`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-solid-active`, `--slotted-tone-accent-solid-hover`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-surface`, `--slotted-tone-secondary-subtle-hover`

## Examples

See [checkbox.examples.md](./checkbox.examples.md).
