Skip to content

Design system

Documentation

DesignComponents / Checkbox

Components / Checkbox

Stable

Checkbox

Use Checkbox for independent choices that can be selected together, submitted in a form, or used as a parent selection control.

On this page

Examples

Basic choice

A labeled checkbox supports a native binary choice in a form or settings group.

Receive one summary each Monday.

Labeled Checkbox with supporting description

Density

Use sm, md, or lg so the control matches the surrounding form rhythm.

Checkbox small, default, and large sizes

Controlled state

Feature state owns the checked value when another part of the screen depends on it.

Controlled Checkbox preview

Indeterminate selection

A parent checkbox communicates that only some visible rows are selected.

Indeterminate parent Checkbox and child choices

Disabled, read-only, and invalid

Unavailable and validation states remain paired with readable context.

This choice is required.

Checkbox disabled, read-only, and invalid states

Native form value

name, value, required, and uncheckedValue integrate with a native form.

Checkbox with native form attributes

When to use

Use a checkbox when several independent options may be selected together. Use RadioGroup for one choice from a set, and Switch when a setting takes effect immediately.

Usage

checkbox-basic.tsx
"use client";

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

export function Example() {
  return (
    <Field>
      <FieldLabel htmlFor="checkbox-digest">Weekly digest</FieldLabel>
      <div className="flex items-center gap-2">
        <Checkbox id="checkbox-digest" name="digest" value="enabled" />
        <FieldDescription>Receive one summary each Monday.</FieldDescription>
      </div>
    </Field>
  );
}

Pair the control with a visible FieldLabel. Keep validation and selection business rules in the feature; Checkbox only exposes the control state.

States

Checkbox states
StateGuidance
checkedControlled state for a feature-owned value.
defaultCheckedInitial state for a local uncontrolled form control.
indeterminateUse for a parent selection when only some child values are selected.
disabled / readOnlyKeep the reason understandable without relying on color.

API

Component API
PropTypeDefaultDescriptionConstraints
checked / defaultCheckedbooleanfalseControlled or initial selection state.Choose one state model per instance.
onCheckedChange(checked, details) => voidCalled when the selection changes.Update controlled feature state here.
size"sm" | "md" | "lg""md"Control density for the square and its indicator.Match the surrounding form rhythm.
indeterminatebooleanfalseDisplays a mixed selection state.Use for a parent checkbox, not as a third submitted value.
disabled / readOnly / requiredbooleanfalseNative interaction and form semantics.Pair non-obvious constraints with visible text.
name / value / form / uncheckedValuestringNative form submission fields.Use stable names in a form.
className / ref / renderstring / Ref / elementStyle extension and Base UI composition.Preserve the checkbox semantics when composing.

Tokens

Component tokens
TokenRoleEffective valueUsage
--radius-smCheckbox radius0.375remKeeps the square control softly rounded across sizes.
--color-action-primary / --color-border-strongSelectionsemantic rolesChecked and unchecked states remain distinct in both themes.
--focus-ring-*Keyboard focusshared ringKeeps Space activation visible.

Accessibility

  • Give every Checkbox a visible label or an explicit accessible name.
  • Use aria-checked="mixed" through indeterminate for partial selection.
  • Verify Space toggles the control and that the label is part of the accessible name.
  • RadioGroup handles mutually exclusive choices.
  • Field connects labels, descriptions, and errors.
  • Data table composes Checkbox for visible-row selection.