Skip to content
Redpanda UI
Esc
↑↓navigate↵open⌘Jpreview
Made by imskyleen
Edit on GitHub

Checkbox

A control that lets the user turn an option on or off, or pick several options from a list, with checked, unchecked and indeterminate states.

Installation

bash
npx shadcn@latest add @redpanda/checkbox
bash
pnpm dlx shadcn@latest add @redpanda/checkbox
bash
yarn dlx shadcn@latest add @redpanda/checkbox
bash
bunx shadcn@latest add @redpanda/checkbox
bash
nubx shadcn@latest add @redpanda/checkbox
bash
aube dlx shadcn@latest add @redpanda/checkbox

Usage

The Checkbox component provides a visually appealing checkbox with smooth animations and comprehensive accessibility support.

tsx
import { Checkbox } from "@/components/redpanda-ui/checkbox"
// Basic checkbox<Checkbox id="terms" />
// Controlled checkboxconst [checked, setChecked] = useState(false)<Checkbox  id="newsletter"  checked={checked}  onCheckedChange={setChecked}/>
// With label<div className="flex items-center space-x-2">  <Checkbox id="terms" />  <label htmlFor="terms" className="text-sm font-medium">    Accept terms and conditions  </label></div>
// Disabled checkbox<Checkbox id="disabled" disabled />
// With indeterminate state<Checkbox id="indeterminate" checked="indeterminate" />

When to use

Use this decision tree to determine when to use the Checkbox component:

Use Checkbox when:

  • Users need to select multiple options from a list
  • Confirming agreement (terms, privacy policy)
  • Enabling/disabling individual features or settings
  • Creating multi-select forms
  • Building data tables with row selection
  • Collecting binary preferences (yes/no, on/off)

Don’t use Checkbox for:

  • Single choice from multiple options (use Radio Group)
  • Immediate toggle actions (use Switch)
  • Navigation or triggering actions (use Button)
  • Complex multi-step selections (use Multi-Select)

Anatomy

The Checkbox component is built on Base UI primitives:

plaintext
Checkbox Component Structure:┌─────────────────────────────────────────────────────┐│ <CheckboxPrimitive.Root> (Base UI primitive)       ││ ┌─────────────────────────────────────────────────┐ ││ │ <button> (Interactive element)                  │ ││ │                                                 │ ││ │ Styles Applied:                                 │ ││ │ • Size (20x20px)                                │ ││ │ • Border (2px, changes on state)                │ ││ │ • Background (transparent → filled)             │ ││ │ • Focus ring (for accessibility)                │ ││ │                                                 │ ││ │ ┌─────────────────────────────────────────────┐ │ ││ │ │ <CheckboxPrimitive.Indicator>               │ │ ││ │ │ ┌─────────────────────────────────────────┐ │ │ ││ │ │ │ <svg> (Checkmark icon)                  │ │ │ ││ │ │ │                                         │ │ │ ││ │ │ │ ┌─────────────────────────────────────┐ │ │ │ ││ │ │ │ │ <path> (CSS-animated path)          │ │ │ │ ││ │ │ │ │                                     │ │ │ │ ││ │ │ │ │ Animation States:                   │ │ │ │ ││ │ │ │ │ • unchecked: dashoffset 1, opacity 0│ │ │ │ ││ │ │ │ │ • checked: dashoffset 0, opacity 1  │ │ │ │ ││ │ │ │ │ • Duration: 0.2s with 0.1s delay   │ │ │ │ ││ │ │ │ └─────────────────────────────────────┘ │ │ │ ││ │ │ └─────────────────────────────────────────┘ │ │ ││ │ └─────────────────────────────────────────────┘ │ ││ └─────────────────────────────────────────────────┘ │└─────────────────────────────────────────────────────┘
State Management:• Controlled: Uses checked prop with onCheckedChange• Uncontrolled: Uses defaultChecked prop• Supports indeterminate state for partial selections
Accessibility Features:• Keyboard navigation (Space to toggle)• Focus management with visible focus ring• Screen reader support via Base UI primitives• ARIA attributes automatically applied• Label association through id/htmlFor
Animation System:• Pure CSS transitions (no JS animation library)• Checkmark draws in via stroke-dashoffset + opacity• 500ms color transition for state changes• Box fill leads the checkmark stroke draw-in slightly

Props

Keyboard interactions

Key Action
Tab to the checkbox Focus lands on the checkbox.
Space Toggles between checked / unchecked. Cycles through indeterminate when indeterminate is in use.
Enter Submits the surrounding form — does not toggle the checkbox.

Accessibility

  • Renders as a real <button role="checkbox"> with aria-checked="true" | "false" | "mixed". The component also sets data-state="checked" | "unchecked" | "indeterminate" so existing Tailwind selectors keep working.
  • Always pair with a visible <Label htmlFor>; if the checkbox is inside a <Field> the label wiring is automatic.
  • Use indeterminate visually only (e.g. parent/child tree selection) — the checkbox still flips to checked on next toggle; don’t try to make indeterminate a persistent form value.
  • Group related checkboxes inside a <fieldset> with a <legend> so screen readers announce the group context.

Examples

Default

Days of the week (Maintenance window)

Indeterminate

Parent / select all

Nested hierarchy

Error state

Helper text

Grouped

Form

Credits

  • We use Base UI for the checkbox component.
  • We take our inspiration from Shadcn UI for the checkbox style.

Recent changes

  • patchv1.2.0Pin shipped dependency floors to the version we develop against. Registry items now declare ranges like `^5.1.9` (the actual installed version) instead of collapsing to `^5.0.0`, so consumers start on the known-tested baseline while caret semantics still allow any compatible release within the same major.#133
  • minorv1.1.0Theme docs refresh, readability pass on semantic foregrounds, and consumer-facing Base UI regression fixes.#121
  • minorv1.0.0Post-Base-UI polish. Public API unchanged.#116
  • majorv1.0.0Migrate every Radix-based primitive to `@base-ui/react@^1.4.0` (Base UI).#114
  • patchv0.3.1## 🚧 Updated#112
See full history →

Last updated on

Was this page helpful?