Skip to main content
The Checkbox component allows users to select or deselect options with support for indeterminate states and parent-child relationships.

Installation

npx shadcn@latest add @eo-n/checkbox

Usage

import { Checkbox } from "@/components/ui/checkbox";

export default function Example() {
  return <Checkbox />;
}

Examples

Default

<Checkbox />

With Label

import { Label } from "@/components/ui/label";

<div className="flex items-center space-x-2">
  <Checkbox id="terms" />
  <Label htmlFor="terms">Accept terms and conditions</Label>
</div>

Disabled

<Checkbox disabled />
<Checkbox disabled checked />

Controlled

import { useState } from "react";

function ControlledCheckbox() {
  const [checked, setChecked] = useState(false);

  return (
    <div className="flex items-center space-x-2">
      <Checkbox
        checked={checked}
        onCheckedChange={setChecked}
        id="controlled"
      />
      <Label htmlFor="controlled">
        {checked ? "Checked" : "Unchecked"}
      </Label>
    </div>
  );
}

Indeterminate State

<Checkbox checked="indeterminate" />

Parent Checkbox

Use the parent prop for checkboxes that control child checkboxes in a group.
<Checkbox parent />

API Reference

Checkbox

Extends all props from @base-ui/react Checkbox.Root component.
parent
boolean
default:"false"
Whether this checkbox is a parent checkbox controlling child checkboxes.
checked
boolean | 'indeterminate'
The controlled checked state of the checkbox.
defaultChecked
boolean
The default checked state when uncontrolled.
onCheckedChange
function
Callback fired when the checked state changes.
(checked: boolean | "indeterminate") => void
disabled
boolean
Whether the checkbox is disabled.
required
boolean
Whether the checkbox is required in a form.
name
string
The name attribute for form submission.
value
string
The value attribute for form submission.
className
string
Additional CSS classes to apply.

TypeScript

import { Checkbox as CheckboxPrimitive } from "@base-ui/react";

type CheckboxProps = React.ComponentProps<typeof CheckboxPrimitive.Root> & {
  parent?: boolean;
};

Accessibility

  • Fully keyboard accessible (Space to toggle)
  • Proper ARIA attributes
  • Focus visible indicator
  • Works with form labels
  • Supports indeterminate state
See Checkbox Group for managing multiple related checkboxes.

Build docs developers (and LLMs) love