Pallas UI
DocsComponents
Core Concepts
    • Introduction
    • Getting Started
    • Theming
    • Color Tokens
    • Spacing & Sizing
    • Layout Guide
    • AspectRatio
    • Box
    • Flex
    • Grid
    • Shapes
Previews
    • Accordion
    • Alert
    • Avatar
    • Badge
    • Breadcrumb
    • Button
    • Carousel
    • Checkbox
    • Combobox
    • Command
    • Date Picker
    • Form
    • Input
    • Input OTP
    • Label
    • MenuBar
    • Modal
    • Popover
    • Progress
    • Radio Group
    • Segmented
    • Select
    • Separator
    • Sheet
    • Sidebar
    • Skeleton
    • Slider
    • Spinner
    • Steps
    • Switch
    • Tabs
    • Textarea
    • Toast
    • Tooltip
    • Typography
  1. Components
  2. Checkbox

Checkbox

A control that allows the user to toggle between checked and not checked.

Installation

Install the following dependencies

npm install @radix-ui/react-checkbox

Copy and paste the following code into your project

'use client'
 
import * as CheckboxPrimitive from '@radix-ui/react-checkbox'
import { cx } from '@styled-system/css'
import { styled } from '@styled-system/jsx'
import { type CheckboxVariantProps, checkbox, icon } from '@styled-system/recipes'
import { Check, Minus } from 'lucide-react'
import * as React from 'react'
 
const checkboxToIconSize = {
  sm: 'sm',
  md: 'md',
  lg: 'lg',
  icon: 'md',
} as const
 
const BaseCheckbox = React.forwardRef<
  React.ComponentRef<typeof CheckboxPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & CheckboxVariantProps
>(({ size, className, ...props }, ref) => {
  const styles = checkbox({ size })
  const iconSize =
    typeof size === 'string' && size in checkboxToIconSize
      ? checkboxToIconSize[size as keyof typeof checkboxToIconSize]
      : 'md'
 
  return (
    <CheckboxPrimitive.Root ref={ref} className={cx(styles.root, className)} {...props}>
      <CheckboxPrimitive.Indicator className={styles.indicator}>
        {props.checked === 'indeterminate' ? (
          <Minus className={icon({ size: iconSize })} />
        ) : (
          <Check className={icon({ size: iconSize })} />
        )}
      </CheckboxPrimitive.Indicator>
    </CheckboxPrimitive.Root>
  )
})
BaseCheckbox.displayName = CheckboxPrimitive.Root.displayName
 
export const Checkbox = styled(BaseCheckbox)

Update the import paths to match your project setup

Usage

import { Checkbox } from '@/components/ui/checkbox'
import { Label } from '@/components/ui/label'
 
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
  <Checkbox id="terms" />
  <Label htmlFor="terms">Accept terms and conditions</Label>
</div>

Props

PropTypeDefault
checkedboolean | 'indeterminate'-
defaultCheckedboolean | 'indeterminate'-
onCheckedChange(checked: boolean | 'indeterminate') => void-
disabledbooleanfalse
requiredbooleanfalse
namestring-
valuestring'on'
size'sm' | 'md' | 'lg''md'

Data Attributes

The following data attributes are available on the root element:

AttributeValues
[data-state]'checked' | 'unchecked' | 'indeterminate'
[data-disabled]Present when disabled

Examples

States

With text

Disabled

Sizes

Built with ❤️ by the carbonteq team. The source code is available on GitHub.

© 2025 Pallas UI. All rights reserved.