# Checkbox

A native `input type="checkbox"` with a styled indicator for checked and indeterminate. Inside a `Field` it takes the field's id, `disabled`, `required` and ARIA wiring.

## Use for

- a checkbox in a form
- a select-all checkbox with an indeterminate state
- a row selection checkbox

## Practices

- Do: Put it in a `Field` with a `Field.Label` so it gets a label and its messages.
- Do: Use `indeterminate` for a select-all when only some rows are selected.
- Don't: Expect `xstyle` to reach the input. It styles the wrapper (`cl-checkbox`); every other prop and the ref go to the input.

## API reference

### Checkbox

A wrapper `span` around the input (`cl-checkbox-input`) and two indicators (`cl-checkbox-indicator` with `data-state`). The wrapper carries `data-size` and `data-disabled`.

Slot: `cl-checkbox`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `'sm' \| 'md'` | `'md'` | `sm` or `md`. |
| `indeterminate` | `boolean` | `false` | Sets the input to its indeterminate state. |

## Examples

### In a field

```tsx
<Field.Root orientation='horizontal'>
  <Checkbox checked={accepted} onChange={e => setAccepted(e.target.checked)} />
  <Field.Content>
    <Field.Label>{m.acceptTerms}</Field.Label>
  </Field.Content>
</Field.Root>
```

## Related

- [Field](/docs/components/field.md)
- [useForm](/docs/hooks/use-form.md)
