# Checkbox

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

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).



<ComponentPreview name="checkbox-demo" previewClassName="h-80" />

## Installation [#installation]

<Tabs defaultValue="cli">
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add https://shadcn-cssinjs.com/r/checkbox.json
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Install the following dependencies:
      </Step>

      ```bash
      pnpm add @base-ui/react @stylexjs/stylex
      ```

      <Step>
        Make sure [StyleX is configured](/docs/installation) and the design tokens are
        installed.
      </Step>

      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource name="checkbox" title="checkbox.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</Tabs>

## Usage [#usage]

```tsx
import { Checkbox } from "@/components/ui/checkbox";
```

```tsx
<Checkbox />
```

## Checked State [#checked-state]

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

```tsx showLineNumbers
import * as React from "react";

export function Example() {
  const [checked, setChecked] = React.useState(false);

  return <Checkbox checked={checked} onCheckedChange={setChecked} />;
}
```

## Invalid State [#invalid-state]

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

<ComponentPreview name="checkbox-invalid" />

## Basic [#basic]

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

<ComponentPreview name="checkbox-basic" />

## Description [#description]

Use `FieldContent` and `FieldDescription` for helper text.

<ComponentPreview name="checkbox-description" />

## Disabled [#disabled]

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

<ComponentPreview name="checkbox-disabled" />

## Group [#group]

Use multiple fields to create a checkbox list.

<ComponentPreview name="checkbox-group" />

## Table [#table]

<ComponentPreview name="checkbox-table" previewClassName="p-4 md:p-8" />

## RTL [#rtl]

To enable RTL support in shadcn/ui, see the [RTL configuration guide](/docs/rtl).

<ComponentPreview name="checkbox-rtl" direction="rtl" previewClassName="h-80" />

## API Reference [#api-reference]

See the [Base UI](https://base-ui.com/react/components/checkbox#api-reference) documentation for more information.
