The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
---
title: Checkbox
description: Select independent options with checked and indeterminate states.
---
import { PageBanner } from "/snippets/page-banner.mdx"
import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import CheckboxReference from '/snippets/ui/generated/input/checkbox.mdx';
## Overview
Use `Checkbox` when each option can be selected independently. For a mutually exclusive choice, use [RadioGroup](/ui/primitives/input/radio-group).
<StoryEmbed
storyId="ui-input-checkbox-checkbox--display"
title="Checkbox example"
height={100}
/>
## Usage
### Uncontrolled state
Use `defaultChecked` to set the initial checked state. The checkbox owns subsequent changes.
```tsx
import { useId } from 'react';
import { Checkbox } from 'twenty-ui/primitives/input';
import { Text } from 'twenty-ui/primitives/typography';
export const EmailPreference = () => {
const checkboxId = useId();
return (
<label
htmlFor={checkboxId}
style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}
>
<Checkbox id={checkboxId} name="updates" value="email" defaultChecked />
<Text render={<span />}>Receive product updates</Text>
</label>
);
};
```
A checked, named checkbox contributes its value to a form. Set `uncheckedValue` if the form should also submit a value when it is unchecked.
## Appearance and interaction
Compare checked, indeterminate, and disabled states, then choose the color, size, shape, and variant independently. The enabled examples can be toggled.
<StoryEmbed
storyId="ui-input-checkbox-checkbox--catalog"
title="Appearance and interaction for checkbox"
height={400}
/>
| Prop | Values | Default |
| --------- | ------------------------------ | -------- |
| `size` | `sm`, `md` | `sm` |
| `variant` | `solid`, `outline`, `soft` | `solid` |
| `shape` | `square`, `round` | `square` |
| `color` | `accent`, `success`, `warning` | `accent` |
Tab focuses the checkbox and Space toggles it. Clicking its label also toggles it. Use `disabled` to prevent interaction, or `readOnly` when the value should remain unchanged while the control stays focusable. Keep meaning in the label rather than communicating it through color alone.
## Controlled state
Pass `checked` and update it with `onCheckedChange` to own the same preference in React state. The callback receives the next boolean and event details.
```tsx
import { useId, useState } from 'react';
import { Checkbox } from 'twenty-ui/primitives/input';
import { Text } from 'twenty-ui/primitives/typography';
export const EmailPreference = () => {
const checkboxId = useId();
const [checked, setChecked] = useState(true);
return (
<label
htmlFor={checkboxId}
style={{ display: 'inline-flex', alignItems: 'center', gap: 8 }}
>
<Checkbox
id={checkboxId}
name="updates"
value="email"
checked={checked}
onCheckedChange={setChecked}
/>
<Text render={<span />}>Receive product updates</Text>
</label>
);
};
```
## Indeterminate state
An indeterminate checkbox represents a partial selection. Derive it from the child options independently of the checkbox's checked state.
```tsx
import { useState } from 'react';
import { Checkbox } from 'twenty-ui/primitives/input';
export const ColumnSelection = () => {
const [showEmail, setShowEmail] = useState(true);
const [showPhone, setShowPhone] = useState(false);
return (
<fieldset>
<legend>Visible columns</legend>
<label>
<Checkbox
checked={showEmail && showPhone}
indeterminate={showEmail !== showPhone}
onCheckedChange={(checked) => {
setShowEmail(checked);
setShowPhone(checked);
}}
/>
All columns
</label>
<label>
<Checkbox checked={showEmail} onCheckedChange={setShowEmail} />
Email
</label>
<label>
<Checkbox checked={showPhone} onCheckedChange={setShowPhone} />
Phone
</label>
</fieldset>
);
};
```
## Parts and custom content
`Checkbox` assembles the styled root and its default check and indeterminate icons. Use `Checkbox.Root` with `Checkbox.Indicator` to own the indicator content. Root owns state and box appearance; Indicator renders the content you supply.
```tsx
import { IconCheck } from 'twenty-ui/icon';
import { Checkbox } from 'twenty-ui/primitives/input';
export const CustomPreference = () => (
<Checkbox.Root aria-label="Updates" defaultChecked>
<Checkbox.Indicator>
<IconCheck aria-hidden />
</Checkbox.Indicator>
</Checkbox.Root>
);
```
`CheckboxRootProps` and `CheckboxIndicatorProps` are public types exported from `twenty-ui/primitives/input`. Both parts accept native attributes, handlers, refs, `render`, and state-based `className` and `style` callbacks. Root's `ref` targets the visible control; `inputRef` targets the native input. The part ref targets its rendered element. Pass `nativeButton` with `render={<button />}` when replacing Root with a button. Appearance props belong on Root; explicit classes and styles are merged with the defaults.
Indicator receives checked and indeterminate state, including transition state. Set `keepMounted` to retain an unchecked indicator in the DOM; the default styling hides it with opacity. Override its `style` or `className` for custom transitions.
<StoryEmbed
storyId="ui-input-checkbox-parts--composition"
title="Checkbox part composition"
height={100}
/>
The callable assembly and its `CheckboxProps` type remain supported. Replace the assembly with Root and its part when supplying custom icons instead of appending another part to the assembly's children.
For controlled form reset, handle the form's `onReset` and restore `checked` to your initial value. Base UI 1.8 does not restore uncontrolled component state on native form reset. `required`, `form`, `value`, and `uncheckedValue` keep the upstream native input behavior.
## Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.
<CheckboxReference />
<PageBanner illustration="page-cover-checkbox" />