Checkboxes are one of the most commonly used form elements in modern web applications. They’re useful for settings pages, task managers, surveys, forms, and anywhere users need to select one or more options.
In this guide, you’ll learn how to create a simple Shadcn Checkbox component using React, Next.js, and Tailwind CSS. I’ll also show tha how to install the component into your own projects.

Basic Shadcn Checkbox
This Basic Shadcn Checkbox is a lightweight, accessible checkbox component built with React and Tailwind CSS. It provides a solid foundation for handling single-option selections and can be easily customized to match your application's design.
Install Shadcn Checkbox
The easiest way to add the Checkbox component is with the Shadcn CLI.
pnpm dlx shadcn@latest add checkboxAfter installation, you can import the component and use it as either a controlled or uncontrolled checkbox using
checked,onCheckedChange, ordefaultChecked.
Manual Installation
If you prefer to create the component manually, install the required dependency:
bun add @base-ui/reactThen create the Checkbox component using the code below.
"use client"
import * as React from "react"
import { CheckIcon } from "lucide-react"
import { Checkbox as CheckboxPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
>
<CheckIcon />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }

Join the conversation! Your thoughts help the community grow.