shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/radix/checkbox.jsonnpx shadcn@latest add https://kit.dev/r/radix/checkbox.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/checkbox.jsonyarn shadcn@latest add https://kit.dev/r/radix/checkbox.jsonInstall the following dependencies:
bun add radix-ui lucide-reactnpm install radix-ui lucide-reactpnpm add radix-ui lucide-reactyarn add radix-ui lucide-reactCopy and paste the following code into your project.
"use client";
import { CheckIcon } from "lucide-react";
import { Checkbox as CheckboxPrimitive } from "radix-ui";
import type React from "react";
import { cn } from "@/lib/utils";
export const Checkbox = (
props: React.ComponentProps<typeof CheckboxPrimitive.Root>
) => {
const { className, ...rest } = props;
return (
<CheckboxPrimitive.Root
className={cn(
"cn-checkbox peer relative shrink-0 outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}Update the import paths to match your project setup.
Anatomy
Checkbox
├── CheckboxLabel
├── checkboxVariants
└── CheckboxIndicatorUsage
import { Checkbox } from "@/components/ui/checkbox";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";<FieldGroup className="w-fit whitespace-nowrap">
<Field orientation="horizontal">
<Checkbox name="terms" />
<FieldLabel>Accept terms</FieldLabel>
</Field>
</FieldGroup>Accessibility
| Key | Description |
|---|---|
Space | Activate the focused control. |
Demos
Invalid
Set aria-invalid on the checkbox and data-invalid on the field wrapper to show the invalid styles.
Basic
Pair the checkbox with Field and FieldLabel for proper layout and labeling.
Description
Use FieldContent and FieldDescription for helper text.
Disabled
Use the disabled prop to prevent interaction and add the data-disabled attribute to the Field for disabled styles.
Group
Use multiple fields to create a checkbox list.
Table
Checkboxes in a table for row selection.
Rtl
Right-to-left checkbox. See the RTL configuration guide for document direction.
API Reference
Checkbox
label
PropType
checkedCheckedState): voidrequired?booleanAttributeType
CheckboxIndicator
div
PropType
checkedCheckedState): voidrequired?booleanAttributeType