Skip to content
GitHub

Checkbox

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

By clicking this checkbox, you agree to the terms.

"use client";
import { Checkbox } from "@/components/ui/pxl/checkbox";
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
FieldTitle,
} from "@/components/ui/pxl/field";
import { Label } from "@/components/ui/pxl/label";
export default function CheckboxDemo() {
return (
<FieldGroup className="max-w-sm">
<Field orientation="horizontal">
<Checkbox id="terms-checkbox" name="terms-checkbox" />
<Label htmlFor="terms-checkbox">Accept terms and conditions</Label>
</Field>
<Field orientation="horizontal">
<Checkbox
id="terms-checkbox-2"
name="terms-checkbox-2"
defaultChecked
/>
<FieldContent>
<FieldLabel htmlFor="terms-checkbox-2">
Accept terms and conditions
</FieldLabel>
<FieldDescription>
By clicking this checkbox, you agree to the terms.
</FieldDescription>
</FieldContent>
</Field>
<Field orientation="horizontal" data-disabled>
<Checkbox id="toggle-checkbox" name="toggle-checkbox" disabled />
<FieldLabel htmlFor="toggle-checkbox">Enable notifications</FieldLabel>
</Field>
<FieldLabel>
<Field orientation="horizontal">
<Checkbox id="toggle-checkbox-2" name="toggle-checkbox-2" />
<FieldContent>
<FieldTitle>Enable notifications</FieldTitle>
<FieldDescription>
You can enable or disable notifications at any time.
</FieldDescription>
</FieldContent>
</Field>
</FieldLabel>
</FieldGroup>
);
}
pnpm dlx shadcn@latest add pxl-ui/registry/checkbox
import { Checkbox } from "@/components/ui/pxl/checkbox"
<Checkbox />

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

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

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

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

Use FieldContent and FieldDescription for helper text.

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

Use multiple fields to create a checkbox list.

See the Base UI documentation for more information.