Skip to main content

Installation

npx shadcn@latest add checkbox

Usage

import { Checkbox } from "@/components/ui/checkbox"
<Checkbox />

Component Code

"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 size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
        className
      )}
      {...props}
    >
      <CheckboxPrimitive.Indicator
        data-slot="checkbox-indicator"
        className="grid place-content-center text-current"
      >
        <CheckIcon className="size-3.5" />
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  )
}

export { Checkbox }

Examples

A basic checkbox.
<Checkbox />

States

The Checkbox component supports the following states:
  • Unchecked - Default state
  • Checked - When the checkbox is selected
  • Indeterminate - For partial selection (e.g., select all)
  • Disabled - When the checkbox cannot be interacted with

Accessibility

The Checkbox component:
  • Uses native checkbox semantics
  • Supports keyboard navigation
  • Works with screen readers
  • Implements proper ARIA attributes
  • Can be controlled or uncontrolled

API Reference

Checkbox

PropTypeDefault
checkedboolean | "indeterminate"-
defaultCheckedboolean-
onCheckedChange(checked: boolean) => void-
disabledbooleanfalse
requiredbooleanfalse
namestring-
valuestring-
classNamestring-

Build docs developers (and LLMs) love