> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Checkbox

A box that toggles a check mark on tap, with its label beside it.


## Installation

```bash
npx @blotch/dolan add checkbox
```

```typescript
import { UiCheckbox } from '../components/ui/checkbox';
```

## Usage

```typescript title="src/app/app.ts"
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
import { UiCheckbox } from '../components/ui/checkbox';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS, UiCheckbox],
  template: ` <ui-checkbox [(checked)]="accepted" label="Accept the terms" /> `,
})
export class App {
  protected readonly accepted = signal(false);
}
```

- **The whole row toggles it**, label included. On a phone the words are the easier target.
- The row is 44px tall at least, and a long label wraps beside the box.
- The check mark pops in and out when the state changes.

### Without a label

```angular-html
<view class="flex flex-row items-center gap-3">
  <ui-checkbox [(checked)]="done" accessibility-label="Done" />
  <text class="text-base text-foreground">Buy milk</text>
</view>
```

- Without a `label`, the checkbox is only the box: 22px, lined up with what's around it.
- Its tap area still reaches 48px across, a comfortable size for a finger, without taking that room in the layout.
- Give it an `accessibility-label`, so a screen reader can name it.

### Disabled

```angular-html
<ui-checkbox disabled />

<ui-checkbox disabled [checked]="true" />
```

A disabled checkbox dims and ignores taps.

### Listen without a signal

```angular-html
<ui-checkbox (changed)="onNewsletter($event)" />
```

`changed` emits the new state after each tap.

### Forms

`checked` is a `model()`, so it works with every Angular forms API:

```angular-html
<ui-checkbox [formField]="profile.field" />
<ui-checkbox [formControl]="control" />
<ui-checkbox [(ngModel)]="value" />
```

A tap marks the field touched, so its error can show. `UiCheckbox` implements Signal Forms' `FormCheckboxControl`. See [Forms](/guide/forms.md).

## API

### UiCheckbox

| Input                 | Type      | Default | Description                                                         |
| --------------------- | --------- | ------- | ------------------------------------------------------------------- |
| `checked`             | `boolean` | `false` | Whether it's checked. Supports `[(checked)]`.                       |
| `label`               | `string`  | `''`    | Text beside the box. The whole row then toggles the checkbox.       |
| `accessibility-label` | `string`  | `''`    | What a screen reader calls a checkbox without a `label`.            |
| `disabled`            | `boolean` | `false` | Dims the checkbox and ignores taps.                                 |
| `class`               | `string`  | `''`    | Extra Tailwind classes for the checkbox: the row, or the box alone. |

| Output          | Type      | Description                                                |
| --------------- | --------- | ---------------------------------------------------------- |
| `changed`       | `boolean` | Emits the new state after a tap.                           |
| `checkedChange` | `boolean` | Emits the new state, for `[(checked)]`.                    |
| `touch`         | `void`    | Emits after a tap, for forms: the field counts as touched. |

`UiCheckbox` also has a public `toggle()` method, which does nothing while disabled.

## Accessibility

- A screen reader reads the checkbox as one button, named by its `label` (or `accessibility-label`), with the value "Checked" or "Unchecked", in the words of [`provideAccessibilityWords()`](/guide/accessibility.md#say-states-in-your-apps-language) when the app gives its own.
- A disabled checkbox is read as dimmed.

## Related

- [Switch](/dolan/switch.md): an on/off control for settings
- [Radio Group](/dolan/radio-group.md): pick one of several options
- [Label](/dolan/label.md): a label of your own, beside a checkbox without one
