Checkbox
A control that allows the user to toggle between checked, unchecked, and indeterminate states.
Usage
import { Checkbox } from "@/components/ui/checkbox"<Checkbox />Examples
With label
<div className="flex items-center gap-2">
<Checkbox id="newsletter" defaultChecked />
<Label htmlFor="newsletter">Subscribe to newsletter</Label>
</div>Disabled
<Checkbox disabled />
<Checkbox disabled defaultChecked />Group
<FieldSet>
<FieldLegend>Notifications</FieldLegend>
<div className="flex flex-col gap-2">
<div className="flex items-center gap-2">
<Checkbox id="email" defaultChecked />
<Label htmlFor="email">Email</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="push" defaultChecked />
<Label htmlFor="push">Push</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox id="sms" />
<Label htmlFor="sms">SMS</Label>
</div>
</div>
</FieldSet>With description
Receive emails about new products, features, and more.
<Field orientation="horizontal">
<Checkbox id="marketing" />
<FieldContent>
<FieldLabel htmlFor="marketing">Marketing emails</FieldLabel>
<FieldDescription>Receive emails about new products, features, and more.</FieldDescription>
</FieldContent>
</Field>Invalid
You must accept the terms to continue.
<Field orientation="horizontal" data-invalid>
<Checkbox id="terms" aria-invalid />
<FieldContent>
<FieldLabel htmlFor="terms">Accept terms and conditions</FieldLabel>
<FieldError>You must accept the terms to continue.</FieldError>
</FieldContent>
</Field>Table
| Name | Role | ||
|---|---|---|---|
| Alice Martin | alice@example.com | Admin | |
| Bob Johnson | bob@example.com | Member | |
| Carol White | carol@example.com | Viewer |
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-10"><Checkbox /></TableHead>
<TableHead>Name</TableHead>
<TableHead>Email</TableHead>
<TableHead>Role</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell><Checkbox /></TableCell>
<TableCell>Alice Martin</TableCell>
<TableCell>alice@example.com</TableCell>
<TableCell>Admin</TableCell>
</TableRow>
<TableRow>
<TableCell><Checkbox defaultChecked /></TableCell>
<TableCell>Bob Johnson</TableCell>
<TableCell>bob@example.com</TableCell>
<TableCell>Member</TableCell>
</TableRow>
<TableRow>
<TableCell><Checkbox /></TableCell>
<TableCell>Carol White</TableCell>
<TableCell>carol@example.com</TableCell>
<TableCell>Viewer</TableCell>
</TableRow>
</TableBody>
</Table>Card
Receive push alerts on your devices.
<div className="grid gap-3">
<FieldLabel>
<Field orientation="horizontal">
<Checkbox id="email" defaultChecked />
<FieldContent>
<FieldLabel htmlFor="email">Email notifications</FieldLabel>
<FieldDescription>Get notified when someone mentions you.</FieldDescription>
</FieldContent>
</Field>
</FieldLabel>
<FieldLabel>
<Field orientation="horizontal">
<Checkbox id="push" />
<FieldContent>
<FieldLabel htmlFor="push">Push notifications</FieldLabel>
<FieldDescription>Receive push alerts on your devices.</FieldDescription>
</FieldContent>
</Field>
</FieldLabel>
</div>Last updated on