# Checkbox

Binary and indeterminate selection built on Base UI.

Binary and indeterminate selection built on Base UI. Unchecked controls use a semantic input border
so their shape remains visible across light and dark surfaces.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/checkbox">Base UI Checkbox</a> for
  upstream behavior and configuration. Zenos owns the public API, styling, and composition shown on
  this page.
</p>

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";

function CheckboxExample() {
  return (
    <Stack direction="row" gap="6" align="center" wrap="wrap" className="justify-center">
      <Stack direction="row" gap="2" align="center">
        <Checkbox id="checkbox-unchecked" />
        <Label htmlFor="checkbox-unchecked">Unchecked</Label>
      </Stack>
      <Stack direction="row" gap="2" align="center">
        <Checkbox id="checkbox-checked" defaultChecked />
        <Label htmlFor="checkbox-checked">Checked</Label>
      </Stack>
      <Stack direction="row" gap="2" align="center">
        <Checkbox id="checkbox-mixed" defaultChecked="indeterminate" />
        <Label htmlFor="checkbox-mixed">Indeterminate</Label>
      </Stack>
    </Stack>
  );
}
```

## Import

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";
```

## Sizes

Use `size="sm"`, `size="md"`, or `size="lg"` for 32px, 40px, or 48px hit targets. The visible boxes scale to 16px, 20px, and 24px.

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";

function CheckboxSizesExample() {
  return (
    <Stack direction="row" gap="6" align="center" wrap="wrap" className="justify-center">
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-sm" size="sm" defaultChecked />
        <Label htmlFor="checkbox-sm">Small</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-md" size="md" defaultChecked />
        <Label htmlFor="checkbox-md">Medium</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-lg" size="lg" defaultChecked />
        <Label htmlFor="checkbox-lg">Large</Label>
      </Stack>
    </Stack>
  );
}
```

## States

Checkbox supports native required, disabled, and invalid semantics. Disabled controls cannot be changed or submitted.

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";

function CheckboxStatesExample() {
  return (
    <Stack gap="4" className="w-full max-w-sm">
      <Stack direction="row" gap="2" align="center">
        <Checkbox id="checkbox-default" />
        <Label htmlFor="checkbox-default">Default</Label>
      </Stack>
      <Stack direction="row" gap="2" align="center">
        <Checkbox id="checkbox-required" required />
        <Label htmlFor="checkbox-required">Accept the terms (required)</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-invalid" aria-invalid="true" />
        <Label htmlFor="checkbox-invalid">Invalid</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-invalid-checked" aria-invalid defaultChecked />
        <Label htmlFor="checkbox-invalid-checked">Invalid checked</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-invalid-mixed" aria-invalid defaultChecked="indeterminate" />
        <Label htmlFor="checkbox-invalid-mixed">Invalid indeterminate</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-disabled" disabled />
        <Label htmlFor="checkbox-disabled">Disabled</Label>
      </Stack>
      <Stack direction="row" gap="1" align="center">
        <Checkbox id="checkbox-disabled-checked" disabled defaultChecked />
        <Label htmlFor="checkbox-disabled-checked">Disabled checked</Label>
      </Stack>
    </Stack>
  );
}
```

## Controlled and indeterminate

Use the indeterminate state for a parent choice when only some child choices are selected.

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";
import { useState } from "react";

function CheckboxControlledExample() {
  const [selected, setSelected] = useState(["alerts"]);
  const options = ["alerts", "reports"];
  const allSelected = selected.length === options.length;
  const parentState = allSelected ? true : selected.length ? "indeterminate" : false;

  return (
    <Stack gap="3" className="w-full max-w-sm">
      <Stack direction="row" gap="2" align="center">
        <Checkbox
          id="checkbox-all"
          checked={parentState}
          onCheckedChange={(checked) => setSelected(checked ? options : [])}
        />
        <Label htmlFor="checkbox-all">All notifications</Label>
      </Stack>
      <Stack gap="3" className="ps-6">
        {options.map((option) => (
          <Stack key={option} direction="row" gap="2" align="center">
            <Checkbox
              id={`checkbox-${option}`}
              checked={selected.includes(option)}
              onCheckedChange={(checked) =>
                setSelected((current) =>
                  checked ? [...current, option] : current.filter((item) => item !== option),
                )
              }
            />
            <Label htmlFor={`checkbox-${option}`} className="capitalize">
              {option}
            </Label>
          </Stack>
        ))}
      </Stack>
    </Stack>
  );
}
```

## Custom indicator

Use the compound API when the default check and dash marks do not fit the surrounding interface.

```tsx
import { Checkbox, Label, Stack } from "@zentara-co/zenos-ui";

function CheckboxCustomIndicatorExample() {
  return (
    <Stack direction="row" gap="2" align="center">
      <Checkbox.Root id="checkbox-custom" defaultChecked>
        <Checkbox.Indicator>
          <span aria-hidden="true" className="text-[11px] leading-none">
            ●
          </span>
        </Checkbox.Indicator>
      </Checkbox.Root>
      <Label htmlFor="checkbox-custom">Custom indicator</Label>
    </Stack>
  );
}
```

## Anatomy

```text
Checkbox.Root
Checkbox.Indicator
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| checked | boolean \| indeterminate | — | Controlled checked state. |
| defaultChecked | boolean \| "indeterminate" | — | Initial uncontrolled checked state. |
| indeterminate / defaultIndeterminate | boolean | false | Controlled or initial mixed state aliases. |
| onCheckedChange | (checked) => void | — | Runs when state changes. |
| size | sm \| md \| lg | md | 32px, 40px, or 48px hit target. |
| disabled / required | boolean | false | Native form semantics. |
| name / value | string | — | Native form submission metadata. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Associate every checkbox with a visible `Label` using matching `id` and `htmlFor` values, or provide an accessible name directly. Space toggles a focused checkbox. The indeterminate state is announced as mixed, while `disabled`, `required`, and `aria-invalid` preserve their native or Base UI semantics.

Source: https://zenos-ui.pages.dev/components/checkbox/