Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Slider
- 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 function CheckboxDemo() {
return (
<Label>
<Checkbox />
Accept terms and conditions
</Label>
)
}
Installation
pnpm dlx shadcn@latest add https://coss.com/ui/r/checkbox.json
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 function CheckboxDisabledDemo() {
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 function CheckboxWithDescriptionDemo() {
const id = React.useId()
return (
<div className="flex items-start gap-2">
<Checkbox id={id} defaultChecked />
<div className="flex flex-col gap-1">
<Label htmlFor={id}>Accept terms and conditions</Label>
<p className="text-xs text-muted-foreground">
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 function CheckboxCardDemo() {
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-xs text-muted-foreground">
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 function CheckboxFormDemo() {
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 onSubmit={onSubmit} className="w-auto">
<Field name="terms">
<FieldLabel>
<Checkbox
name="terms"
value="yes"
defaultChecked
disabled={loading}
/>
Accept terms and conditions
</FieldLabel>
</Field>
<Button type="submit" disabled={loading}>
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.com ui quickly.
Quick Checklist
- If you used
asChild
on parts, switch to therender
prop