110k
New

Checkbox

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

Component checkbox-demo not found in registry.

Installation

pnpm dlx createui@latest add checkbox

Usage

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

Checked State

Use defaultChecked for uncontrolled checkboxes, or checked and onCheckedChange to control the state.

import * as React from "react"
 
export function Example() {
  const [checked, setChecked] = React.useState(false)
 
  return <Checkbox checked={checked} onCheckedChange={setChecked} />
}

Invalid State

Set aria-invalid on the checkbox and data-invalid on the field wrapper to show the invalid styles.

Component checkbox-invalid not found in registry.

Examples

Basic

Pair the checkbox with Field and FieldLabel for proper layout and labeling.

Component checkbox-basic not found in registry.

Description

Use FieldContent and FieldDescription for helper text.

Component checkbox-description not found in registry.

Disabled

Use the disabled prop to prevent interaction and add the data-disabled attribute to the <Field> component for disabled styles.

Component checkbox-disabled not found in registry.

Group

Use multiple fields to create a checkbox list.

Component checkbox-group not found in registry.

Table

Component checkbox-table not found in registry.

API Reference

See the Base UI documentation for more information.