Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- EmptyNew
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input GroupNew
- KbdNew
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- SkeletonNew
- Slider
- SpinnerNew
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Resources
Checkbox
A control allowing the user to toggle between checked and not checked.
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
export default function Particle() {
return (
<Label>
<Checkbox />
Accept terms and conditions
</Label>
);
}
Installation
pnpm dlx shadcn@latest add @coss/checkbox
Usage
import { Checkbox } from "@/components/ui/checkbox"<Checkbox />Examples
For accessible labelling and validation, prefer using the Field component to wrap checkboxes. See the related example: Checkbox field.
Disabled
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
export default function Particle() {
return (
<Label>
<Checkbox defaultChecked disabled />
Accept terms and conditions
</Label>
);
}
With Description
By clicking this checkbox, you agree to the terms and conditions.
import * as React from "react";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
export default function Particle() {
const id = React.useId();
return (
<div className="flex items-start gap-2">
<Checkbox defaultChecked id={id} />
<div className="flex flex-col gap-1">
<Label htmlFor={id}>Accept terms and conditions</Label>
<p className="text-muted-foreground text-xs">
By clicking this checkbox, you agree to the terms and conditions.
</p>
</div>
</div>
);
}
Card Style
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
export default function Particle() {
return (
<Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
<Checkbox defaultChecked />
<div className="flex flex-col gap-1">
<p className="text-sm leading-4">Enable notifications</p>
<p className="text-muted-foreground text-xs">
You can enable or disable notifications at any time.
</p>
</div>
</Label>
);
}
Form Integration
Field provides accessible labelling and validation primitives for form controls. Use it with Form to submit values.
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Field, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
export default function Particle() {
const [loading, setLoading] = React.useState(false);
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
const accepted = formData.get("terms");
alert(`Terms: ${accepted}`);
};
return (
<Form className="w-auto" onSubmit={onSubmit}>
<Field name="terms">
<FieldLabel>
<Checkbox
defaultChecked
disabled={loading}
name="terms"
value="yes"
/>
Accept terms and conditions
</FieldLabel>
</Field>
<Button disabled={loading} type="submit">
Submit
</Button>
</Form>
);
}
Comparing with Radix / shadcn
If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with coss ui quickly.
Quick Checklist
- If you used
asChildon parts, switch to therenderprop