Component guideEditable source

Checkbox

A selectable checkbox with checked, unchecked, and mixed states.

Original component docs
On this page4 sectionsBack to top

Use Checkbox for independent choices or explicit agreement. Use Radio Group when exactly one option is allowed and Switch for an on/off setting.

Live preview
Loading preview...

#Installation

Complete the base setup. For manual installation:

npx shadcn@latest add https://neobrutal-ui.andongmin.com/r/checkbox.json

#Usage

"use client";
import { useState } from "react";
import { Checkbox } from "@/components/ui/checkbox";

export default function ConsentField() {
  const [accepted, setAccepted] = useState(false);
  return (
    <div className="grid gap-3">
      <div className="flex items-center gap-2">
        <Checkbox
          id="terms"
          checked={accepted}
          onCheckedChange={(value) => setAccepted(value === true)}
        />
        <label htmlFor="terms">Accept the terms</label>
      </div>
      <p role="status">{accepted ? "Accepted in this preview." : "Not accepted."}</p>
    </div>
  );
}

#API reference

Prop / partPurposeDefault
checked / defaultCheckedBoolean checked stateUnchecked
onCheckedChangeNew boolean checked state and event details—
indeterminateExplicit mixed state, independent of checkedfalse
disabled / requiredInteraction and form constraintsfalse
name / value / formForm association through a hidden input—
id / inputRefLabel association and hidden input reference—

#Accessibility

Associate a visible label with the checkbox. Space toggles the focused control. Use mixed state for partial selection, not as a third agreement option. Checked state does not submit or save anything on its own. Treat indeterminate as presentation for partial selection; onCheckedChange still reports a boolean checked state.