shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A checkbox is a small box beside a label that someone ticks to say yes to one thing: accepting the terms, picking a filter, selecting a row in a table. Boxes in a list are independent of each other, and each ticked one goes in with the form when it's submitted.
When the change should take effect the moment it's made, such as turning on notifications, use a Switch. When only one option of a few can be picked, use a Radio Group.
Installation
Anatomy

Usage
<script setup lang="ts">
import { Checkbox } from "@/components/ui/checkbox";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
</script>
<template>
<FieldGroup class="w-fit whitespace-nowrap">
<Field orientation="horizontal">
<Checkbox name="terms" />
<FieldLabel>Accept terms</FieldLabel>
</Field>
</FieldGroup>
</template>
Inside one Field, FieldLabel is wired to the checkbox for you: clicking the words ticks the box, and a screen reader reads them as its name.
Accessibility
The box is a <button> with the checkbox role and aria-checked, which reads mixed while checked is "indeterminate", and a hidden native input beside it carries the value for the form. Inside a Field, UI SDK ties it to the FieldLabel, which becomes its name, so clicking the words ticks the box. Where no visible label fits, such as a table cell, point aria-labelledby at the id of the text that names it, or set aria-label.
- Space
- Toggles the checkbox.
- Enter
- Leaves the box as it is and submits the form it belongs to, through the form's default submit button.
Demos
Invalid
An Accept terms box in its error state, the way it should look after someone submits without ticking a box they had to tick. The demo sets invalid on Field and aria-invalid on Checkbox, which turns the border and the label red. Show it only after a submit, with a FieldError that says what's missing.
Basic
An Accept terms box with a label and a name, the smallest checkbox worth shipping. In a form, a ticked box sends its name with the value on, and an unticked one sends nothing. Start here for a single agreement, and add a description only when the label can't carry the consequence on its own.
Description
Accept terms starts ticked, with a second, quieter line under the label. FieldContent stacks the label over that description, and the field then aligns the box with the first line of text instead of centering it on the block. Use it when the label alone would hide a consequence, such as a charge or data being shared, and keep the second line to that consequence.
Disabled
A Notifications box that can't be changed. Checkbox gets disabled and Field gets data-disabled, so the label fades along with the box and clicks do nothing. Use it for a preference the current plan or role doesn't allow, and say why next to it. Leave the row out when the person will never be able to change it.
Group
Three kinds of item to show on the desktop, under a legend that reads Desktop: hard disks and external disks start ticked, servers doesn't. Each box has its own name, so the form sends one entry per ticked box. Put boxes that answer one question in a FieldSet with a FieldLegend, which renders a real fieldset and legend, so a screen reader names the group as focus enters it.
Table
A table of three people with a box in each row and one in the header, with Sarah Chen selected to start. The header box is ticked when every row is and mixed while only some are, and a click on it selects every row or clears them all. The selected ids live in a Set in state, which the boxes and the row highlight both read.
RTL
The Accept terms box in Arabic, with dir set to rtl on the FieldGroup around it. The box moves to the right edge and the label follows it to the left, with no change to the markup. Set the direction on the nearest wrapper like this when the block sits inside a page that otherwise reads left to right.
FAQ
When should I use a checkbox instead of a switch or radio buttons?
Use a checkbox when the choice takes effect later, usually when a form is submitted, and when several options in a list can be picked at once: accepting terms, choosing filters, selecting rows for a bulk action.
A Switch reads as an on and off control that acts immediately, like a setting saved as soon as it changes. A Radio Group is for exactly one choice out of a few, all of them visible. A single box that turns a setting on or off right away is a switch in disguise.
How do I control a Checkbox's checked state in Vue?
Bind v-model:checked to a ref, or pass checked and listen to @checked-change, which receives the new state first and the details second.
The state is true, false or "indeterminate". Use defaultChecked instead when you only need a starting value and the box can keep its own state.
Hold the state yourself when something else reads it, such as a submit button that stays disabled until the terms box is ticked.
How do I make a select-all Checkbox with an indeterminate state?
Set the header box's checked to "indeterminate". It draws a dash, the browser reports it as mixed, and a click on it asks for true.
Work the state out from the rows on every render. Keep the selected ids in a Set: the header is checked when the set holds every row, mixed when it holds some, and on change it fills the set or empties it, as the Table demo does.
How do I add a label to a Checkbox in UI SDK?
Put Checkbox and a FieldLabel in one Field, as the Basic demo does, and UI SDK ties the two together: clicking the words ticks the box and a screen reader reads them as its name, with no ids to write. Where no visible label fits, as in a table row, point aria-labelledby at the id of the text that names the box, as the Table demo does with each row's name.
A visible label also makes the target bigger. The box has an invisible hit area a little wider than itself, but on a phone the words are what people aim for.
How do I show a Checkbox error in a form?
Set invalid on the Field around the box. The field marks the checkbox with aria-invalid, which a screen reader announces and the styles draw as a red border, and the field's label turns red with it.
Put the message in a FieldError inside the same field, so it sits under the label, and show it after a submit rather than while someone is still filling the form in.
What value does a Checkbox send when the form is submitted?
A ticked box sends its name with the value on, or with its value when you set one, and an unticked box sends nothing, the way a native checkbox does. On the server, read a missing key as false.
UI SDK keeps the hidden input in the page whether or not a <form> is around it, and form takes the id of a form the box sits outside. With a form library, bind the library's field to the box's checked state and update the field from the change callback.
How do I get the checked values of a group of checkboxes?
Wrap the boxes in CheckboxGroup and give each Checkbox a value. The group holds an array of the checked values, in the order the boxes appear, and a name on the group goes to every box.
Bind that array with v-model on the group, or pass value and listen to @value-change.
On submit, a FormData built from the form returns every ticked box that shares one name through getAll.
How do I change the Checkbox size or colors?
Edit components/ui/checkbox, which is your file once installed. The box's size, border and checked color are utility classes on the root, and the check icon's size is a class on the indicator, so change those to restyle every checkbox at once.
To change one box, add a class to Checkbox. It is merged over the defaults, so a size or a background color you add there wins over the one in the file.
API Reference
Checkbox
<button> data-slot="checkbox"
checked?boolean
Whether it's checked. Pass it to control the checkbox. Two-way with v-model or v-model:checked.
defaultChecked?boolean
Whether it's checked at first, when uncontrolled. A form reset returns to it.
controller?{ toggle: (details?: Details) → boolean; getChecked: () → CheckedState; setChecked: (checked: CheckedState, details?: Details) → boolean; focus: () → void; }
Toggles it from anywhere. Create one with createCheckboxController().
- Type
{ toggle: (details?: Details) → boolean; getChecked: () → CheckedState; setChecked: (checked: CheckedState, details?: Details) → boolean; focus: () → void; }
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables it like a native control: it can't be focused or changed, and isn't submitted.
form?string
The id of a form to belong to, when it isn't inside that form.
indeterminate?boolean
Shows the mixed state (a dash) whatever checked is, for a partly checked set.
name?string
The name it submits under. Without one, it submits nothing.
parent?boolean
Makes it the parent of its group: it checks or unchecks every checkbox in the group, and shows checked, unchecked or indeterminate from them.
- Default
false
readOnly?boolean
Keeps it focusable and submitted, but stops changes.
required?boolean
Blocks form submission until it's checked, with the browser's own message.
value?string
What it submits while checked.
- Default
"on"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
@checked-change(checked: boolean, details: CheckedChangeDetails) → void
Runs when a press or a form reset wants to change it.
- Type
(checked: boolean, details: CheckedChangeDetails) → void- Parameters
checked– booleandetails– CheckedChangeDetails- Returns
void
data-checked?string
Present while checked.
data-disabled?string
Present when disabled, by its own prop, a group or a <fieldset>.
data-indeterminate?string
Present while indeterminate.
data-readonly?string
Present when read-only.
data-required?string
Present when required.
data-unchecked?string
Present while unchecked.











