On this page

InstallationUsageAnatomySizesUnchecked, checked and someControlledLabel weightDescriptionBadgeInfo iconThe box aloneDisabledInvalidIn a groupSelect allIn a FieldIn the dashboardAPI ReferenceCheckboxCheckboxGroupRulesOpen questionsCheckbox, switch, radio or selectLabelsErrorsSize and spacingAccessibilityWhat others expose

Checkbox

One option to tick or leave: alone as a yes or no, or in a list where any number can be picked. Two sizes, with a label, a description and a third state, “some”, for a Select all.

1<CheckboxGroup defaultValue={["failures"]} aria-label="Email me about">2  <Checkbox value="failures">Run failures</Checkbox>3  <Checkbox value="quota">Quota reached</Checkbox>4  <Checkbox value="summary" description="One email on Monday.">Weekly summary</Checkbox>5</CheckboxGroup>

Installation

import { Checkbox, CheckboxGroup } from "@catalog-developer/components";

Usage

import { Checkbox, CheckboxGroup } from "@catalog-developer/components";
<Checkbox defaultChecked>Run failures</Checkbox>

Anatomy

123456
  1. 1 — Box. Off, the Input: its fill and a 1px ring. On and "some", the primary button. Its edge is a shadow, never a border.
  2. 2 — Glyph. A check when ticked, a bar for "some", in the primary button's text color.
  3. 3 — Label. The text, medium or regular. The box is centered on its first line. A press on it ticks the box.
  4. 4 — Info icon. Opens a tooltip on hover and on focus. A press on it does not tick the box.
  5. 5 — Badge. On the label's line. The line wraps when it runs out of room.
  6. 6 — Description. A line of help, 2px under the label, in the secondary text color.
SizeBoxCornersCheckTextBox to textInfo iconHit area
md14px4px11pxlabel-2, 13px8px12px26px
sm12px3px9pxlabel-3, 12px6px11px24px

Sizes

One size sets the control and its text together. md, the default, is a 14px box with 13px text, 8px apart. sm is a 12px box with 12px text, 6px apart. The description and the info icon follow.

1<Checkbox defaultChecked>Run failures</Checkbox>2<Checkbox size="sm" defaultChecked>Run failures</Checkbox>

Unchecked, checked and some

Off, the box is the Input: its fill and its ring. On, it is the primary button, with a check. defaultChecked says where the box starts. When a box is ticked, the check is drawn left to right in 0.2s, as a hand writes it. It never draws on the page's first paint, and not at all under reduced motion. indeterminate is the third state, "some": a bar in place of the check, for a box that stands for others and has only part of them ticked. A box on its own is ticked or it is not. A parent box in a group works it out, so you rarely set it yourself.

1<Checkbox>Quota reached</Checkbox>2<Checkbox defaultChecked>Quota reached</Checkbox>3<Checkbox indeterminate>Select all</Checkbox>

Controlled

checked with onCheckedChange hands the state to the page. The handler gets a boolean, never "some".

Left out
1const [checked, setChecked] = useState(false);2 3<Checkbox checked={checked} onCheckedChange={setChecked}>4  Include archived agents5</Checkbox>6<Badge color={checked ? "success" : "neutral"}>{checked ? "Included" : "Left out"}</Badge>

Label weight

The text after the box is its label: children. It is medium by default. weight="regular" is for long lists.

1<Checkbox defaultChecked>Run failures</Checkbox>2<Checkbox weight="regular" defaultChecked>Run failures</Checkbox>

Description

description is a line of help under the label, in the secondary text color. A press on it ticks the box, as a press on the label does.

1<Checkbox defaultChecked description="One email on Monday, with the week's runs and failures.">2  Weekly summary3</Checkbox>

Badge

badge sits after the label, on its line. You set the badge's size yourself: md beside an md label, sm beside an sm one.

1<Checkbox badge={<Badge color="fuchsia" size="md">Preview</Badge>}>Anomaly alerts</Checkbox>2<Checkbox size="sm" badge={<Badge color="fuchsia" size="sm">Preview</Badge>}>Anomaly alerts</Checkbox>

Info icon

iconTooltip puts an info icon after the label: 12px beside md text, 11px beside sm. Its tooltip opens on hover and on focus, and Tab reaches it. A press on it never ticks the box.

1<Checkbox iconTooltip="The gateway signs in as itself, with no stored key.">Use workload identity</Checkbox>

The box alone

With no children the Checkbox is the box and nothing else, for a place that names it: a table row, a list header. Give it an aria-label, since nothing else names it for a screen reader. It can be pressed 6px past each edge (26px across at md, 24px at sm), so it needs no padding added to be easy to hit.

1<Checkbox aria-label="Select all rows" indeterminate />2<Checkbox aria-label="Select billing-sync" defaultChecked />

Disabled

disabled draws the box at half strength, with the not-allowed cursor over the box and its text. The box does not tick, and Tab skips it.

1<Checkbox disabled>Quota reached</Checkbox>2<Checkbox disabled defaultChecked>Quota reached</Checkbox>

Invalid

aria-invalid gives the box the Input's error edge, and its error band on focus. The words that say what is wrong belong to a Field.

1<Checkbox aria-invalid>I understand this deletes the workspace</Checkbox>2<Checkbox aria-invalid defaultChecked>I understand this deletes the workspace</Checkbox>

In a group

CheckboxGroup stacks two boxes or more, 8px apart, and holds what is ticked as a list of each box's value. Name the group with aria-label, or put it in a Field. disabled on the group disables every box in it.

1<CheckboxGroup defaultValue={["failures", "summary"]} aria-label="Email me about">2  <Checkbox value="failures">Run failures</Checkbox>3  <Checkbox value="quota">Quota reached</Checkbox>4  <Checkbox value="summary">Weekly summary</Checkbox>5</CheckboxGroup>

Select all

A box with parent on top of a group stands for the whole group. Give the group allValues, every value it holds, and control it with value and onValueChange. The parent is unchecked with nothing ticked, "some" with part, and checked with all. A press on a "some" parent ticks everything, the next press clears everything, and the one after brings back what was ticked before.

1const ALL = ["failures", "quota", "summary"];2const [picked, setPicked] = useState(["failures"]);3 4<CheckboxGroup value={picked} onValueChange={setPicked} allValues={ALL} aria-label="Email me about">5  <Checkbox parent>Select all</Checkbox>6  <Checkbox value="failures">Run failures</Checkbox>7  <Checkbox value="quota">Quota reached</Checkbox>8  <Checkbox value="summary">Weekly summary</Checkbox>9</CheckboxGroup>

In a Field

A Field gives a group its title, its description and its one error. It is written two ways today. The first example leaves htmlFor out: the group takes the Field's title as its name, its description and its error, and while the error is set every box in the group is marked invalid. The second passes htmlFor={null}, as the catalog's Field controls do: the Field is then plain markup, and the group is named by hand. Which to write is an open question below. A lone checkbox needs no Field: its text is its label.

Email me about

Sent to the address you sign in with.

Pick at least one.
Email me about

Sent to the address you sign in with.

1<Field title="Email me about" description="Sent to the address you sign in with." error="Pick at least one.">2  <CheckboxGroup defaultValue={[]}>3    <Checkbox value="failures">Run failures</Checkbox>4    <Checkbox value="quota">Quota reached</Checkbox>5    <Checkbox value="summary">Weekly summary</Checkbox>6  </CheckboxGroup>7</Field>8 9<Field htmlFor={null} title="Email me about" description="Sent to the address you sign in with.">10  <CheckboxGroup defaultValue={["failures"]} aria-label="Email me about">11    <Checkbox value="failures">Run failures</Checkbox>12    <Checkbox value="quota">Quota reached</Checkbox>13    <Checkbox value="summary">Weekly summary</Checkbox>14  </CheckboxGroup>15</Field>

In the dashboard

About 40 checkboxes in 25 files, in seven kinds. The dashboard's own components/ui/checkbox.tsx renders this Checkbox, text props included. No screen uses CheckboxGroup yet: every list keeps its own set of ticked ids.

KindHow it is built todayFile
One option in a formA yes or no sent with the form. Its text is its label, with no Field around it.components/settings/import-export/export-card.tsx
A list to pick fromAny number of tools, each with a description, at regular weight.components/gateway/tool-filter-checklist.tsx
Select all, with “some”A box over every permission. Its word is a span beside the box, and “some” is worked out by hand.components/settings/permission-group-picker.tsx
A table’s rowsThe box alone, named “Select row”. The header’s box is “some” while part of the page is selected.ds/components/table/rows.tsx
With badgesAn event to subscribe to: its name in mono, badges on the label’s line and a description.components/settings/eventing/event-picker.tsx
With an info iconDisabled when the gateway cannot do it. The icon says why.components/models/model-form.tsx
Named by what ticking doesThe text is the workspace alone, so aria-label names each box “Delete workspace” and the workspace.components/billing/cancel-plan-dialog.tsx

API Reference

Checkbox

Besides these, every prop of Base UI's Checkbox.Root (render, nativeButton, style) and of a <span> (title, data-testid, onClick). They land on the box, not on the label around it.

PropTypeDefaultDescription
childrenReactNode—The label, after the box. A press on it ticks the box. With none, the Checkbox is the box alone and needs an aria-label.
size"md" | "sm""md"The control and its text together: a 14px box with 13px text, or a 12px box with 12px text.
weight"medium" | "regular""medium"The label's weight. Regular is for long lists.
descriptionReactNode—A line of help under the label. It describes the box for a screen reader.
badgeReactNode—After the label, on its line: a Badge (Preview, Recommended). md beside md text, sm beside sm.
iconTooltipstring | TooltipSettings—An info icon after the label: its text, or the text with the tooltip's settings (side, align, delay…).
checkedboolean—Whether the box is ticked, when the page holds the state. Pair it with onCheckedChange.
defaultCheckedbooleanfalseWhether the box starts ticked, when it holds its own state.
onCheckedChange(checked: boolean, eventDetails) => void—Called when the box is ticked or cleared. A press on an unticked "some" box reports true.
indeterminatebooleanfalseThe "some" state: the bar in place of the check. A parent box sets it by itself.
disabledbooleanfalseHalf strength, no press, and out of the Tab order.
aria-invalidboolean—The Input's error edge on the box, and its error band on focus.
aria-labelstring—Names a box that has no text. A box with text is named by its text. To name it otherwise, also pass aria-labelledby={undefined}.
parentbooleanfalseMakes the box stand for its whole group: a Select all. Only inside a CheckboxGroup with allValues.
valuestring—What the box is called in its group's list. In a form, what a ticked box submits; with none it submits on.
namestring—The field's name when a form is submitted.
uncheckedValuestring—What an unticked box submits. By default it submits nothing.
formstring—The id of the form that owns the box, when the box sits outside it.
requiredbooleanfalseSets required on the hidden input and aria-required on the box. It draws no mark.
readOnlybooleanfalseA press does not change the box, and it stays in the Tab order. It has no look of its own.
idstring—The id of the hidden input.
inputRefRef<HTMLInputElement>—A ref to the hidden input.
classNamestring—Where the box sits (an alignment, a margin). Its size, corners, fill and ring are size and its state.

CheckboxGroup

Base UI's CheckboxGroup, stacked. Besides these, every prop of a <div>.

PropTypeDefaultDescription
valuestring[]—The values of the boxes that are ticked, when the page holds the list.
defaultValuestring[]—The values ticked at the start, when the group holds its own list.
onValueChange(value: string[], eventDetails) => void—Called with the new list when a box is ticked or cleared.
allValuesstring[]—Every value in the group. A parent box needs it to know what "all" is.
disabledbooleanfalseDisables every box in the group.
aria-labelstring—Names the group, when no Field does.
classNamestring—Added to the stack. The 8px between boxes is built in.

Rules

Open questions

Over a list of choices: htmlFor null, or left out?

Open
Ours

Both are written today, and this page shows both. Left out, a CheckboxGroup or a RadioGroup takes the Field's title, description and error itself. The catalog's Field controls pass null and name the group by hand.

Other systems

Not a question the other systems have: it is about our own prop.

Do we mark the optional fields, or the required ones?

Open
Ours

The optional ones, with a badge. Required has no mark of its own; a field can pass a Required badge through badge.

Other systems

Atlassian and Primer mark the required ones with an asterisk after the label; Primer even when every field is required, and Atlassian adds a line saying what the asterisk means. Polaris's required shows an indicator.

Should the whole row tick the box?

Open
Ours

The label is as wide as its text. In the event picker each row has a hover of its own, but a press beside the text does nothing.

Other systems

Polaris has fill, which grows the label to fill what holds it, and bleed, which pads the label out into the space around it, so that space can be pressed too.

Does every box in an invalid group turn red?

Open
Ours

Yes. While a Field's error is set, the Field marks every box in the group invalid, so each one takes the Input's error edge.

Other systems

Primer: a single checkbox has no validation style or message of its own, and the group shows the message. Atlassian: isInvalid changes the look of an unchecked box.

Can a disabled checkbox take the focus, and where does it say why?

Open
Ours

A disabled box is at half strength and Tab skips it. design/principles.md says a disabled item stays focusable, so the two disagree. The model form disables "Use workload identity" and gives the reason in its info icon.

Other systems

Atlassian: a checkbox that must stay reachable with Tab is left enabled, and an error message gives the reason it cannot be picked.

How much can the info icon hold?

Open
Ours

iconTooltip takes text of any length. The model form's "Use workload identity" puts a whole paragraph there.

Other systems

Polaris: explain a checkbox with a line under it or a link to more, not with a tooltip.

Select all in Settings is built by hand

Open
Ours

CheckboxGroup with allValues and a parent box works out "some". No screen uses it: the permission picker and the export card work it out themselves, two levels deep, and write "Select all" as a span beside the box, so a press on the word does nothing.

Other systems

Base UI's "Nested parent checkbox" example puts one group inside another, each with its own parent box.

Checkbox, switch, radio or select

DoTicked now, applied by the button.
Don’tNo button follows it, so it would act when ticked. That is a Switch.

A checkbox waits for a button. A switch acts at once

Use a checkbox for a choice that is sent later, with the form or the dialog it sits in: ticking it changes nothing until a button is pressed. Use a Switch when the change takes effect the moment it is made.

From Atlassian's toggle page (a toggle never needs a button to apply it, and a setting that does is a checkbox) and Primer's ToggleSwitch guidelines (a switch saves at once, a checkbox waits for a save). Not decided for the dashboard, which also holds switches in forms that have a Save: see the Switch page's open question.

DoExactly one can be chosen.
Don’tBoth can be ticked, and they can't both be true.

Any number of several: checkboxes. Exactly one: radios or a Select

Use checkboxes for a list where none, one or several can be picked, and for one yes or no. Each box answers for itself: only a Select all moves other boxes.

When picking one option rules out the others, use a RadioGroup, or a Select where there is less room.

From Atlassian (radio buttons for a single choice, a dropdown for the same in less room) and Polaris (radio buttons for a single choice; each box stands alone, a select-all aside).

Labels

Dochildren: a press on the words ticks the box.
Select all
Don’tA box and a span beside it: the words do nothing when pressed.

The text is the checkbox's own

Pass the label as children, and its help as description. The Checkbox then sets the type, the gap and the line the box centers on, and ties the words to the box for a screen reader. Never place a label beside a bare box by hand, and never draw the box from a native input or a div: if the Checkbox lacks what you need, add the prop to it and to this page.

Do
Don’tTicking it to turn something off makes people read twice.

Say what ticking does, in the positive

A label names the thing, or says what happens when the box is ticked. Sentence case, a few words, no full stop. A ticked box means yes.

From Polaris (a label is worded positively) and Atlassian (short, with no punctuation after it).

Errors

Don’tRed boxes and no words: nobody knows what to fix.

One error, in words, under the group

The red edge marks where the problem is. A Field's error says what it is, once, under the group, as under In a Field above. Color is never the only signal: the edge always comes with words.

From Primer (the group shows the message, not each box) and Atlassian (a required or invalid checkbox gets an error message).

Size and spacing

Dosize="sm": a 12px box with 12px text.
Don’tAn md box with small text set by a class.

One size sets the control and its text

size sets the box, the label, the description and the info icon in one move. Never size the text with a class, or the box with className. A badge beside the label is md at md and sm at sm.

Dop-card-inset: 16px on all four sides.
Don’tpx-card-inset py-2: 8px above and below, as the export card's Select all row still is.

A row that holds a checkbox pads 16px around it

In a card, a row of text alone pads 12px above and below. A row that holds a control pads the full card inset, 16px, on all four sides, and a checkbox counts as a control. A Field that is a card's row does this by itself.

Accessibility

The box is Base UI's Checkbox: a <span> with the checkbox role, and a hidden native input beside it, so it works in a form and inside a label.

KeyWhat it does
TabMoves to the next box, and Shift+Tab to the one before. Each box is its own stop, in a group too. A disabled box is skipped.
SpaceTicks or clears the box that has the focus.
EnterDoes not tick the box. In a form, it presses the form's submit button (read in Base UI's code, not tried).

Its name. With text, the box is named by its label (aria-labelledby) and described by its description (aria-describedby). With no text it needs an aria-label. The label wraps the box, so a press anywhere on the words ticks it.

Its state. aria-checked is true, false, or mixed for "some", so the bar is not the only signal. A disabled box carries aria-disabled. A parent box points at the boxes it controls with aria-controls.

Groups. A CheckboxGroup has the group role. Name it with aria-label, or put it in a Field: the Field's title then names the group, and its description and error describe every box in it.

The info icon. It is a stop of its own after the box, with the button role, named after the label ("Weekly summary details"). Its tooltip opens on focus.

Focus, errors and motion. Focus shows as the Input's band around the box, and is never removed. An invalid box carries aria-invalid, and its message is the Field's error, in words. The check's drawing and the box's color change stop under reduced motion.

From knowledge, not tested with a screen reader. A screen reader should say the label, "checkbox", its state (checked, not checked or mixed), then the description.

What others expose

Read on the checkbox pages of shadcn/ui, Base UI, Atlassian and GitHub Primer, and in Shopify Polaris's repository (its documentation source and its component). "Ask" means the question is open, under Rules.

WhatWhoVerdict
A label that fills its row, and a pressable area that reaches into the paddingPolaris (fill, bleed)Ask: "Should the whole row tick the box?"
Nested groups, each with a parent boxBase UIAsk: "Select all in Settings is built by hand". The parts exist; no screen uses them.
An error message on the checkbox itselfPolaris (error)Not needed, because a Field carries the one error for a box or a group.
A prop for the invalid stateAtlassian (isInvalid)Not needed, because aria-invalid is the same attribute the Input takes, and shadcn uses it too.
A required prop that restyles the labelAtlassian (isRequired)Ask: nobody has decided whether required fields get a mark. Today required reaches the input and nothing is drawn. Primer marks the group as required, not the box. See the open question on required fields.
A prop that hides the label from the eyePolaris (labelHidden)Not needed, because a box with no children and an aria-label is the same thing. Primer says never to hide it.
An icon before the labelPrimer (a leading visual)Not needed, because the label takes any content, an icon included.
A label part and a description part you compose yourselfshadcn (its Field parts), Primer (its FormControl parts)Not needed, because children and description are built in, so every box is spaced and named the same way.
A second color for the boxPolaris (tone)Not needed, because a checked box has one look: the primary button's.
"Some" as a value of checkedPolaris (checked="indeterminate")Not needed, because indeterminate is a prop of its own, and a parent box works it out from the group.
A right-to-left exampleshadcnNot needed until the dashboard has a right-to-left language.
Props for a test id and for analyticsAtlassian (testId, analyticsContext)Not needed, because data-testid and every other attribute pass through to the box.
Catalog
Foundations
  • Overview
  • Components
  • Tokens
  • Token usage
  • Typography
  • Icons
Atoms
  • Avatar
  • Badge
  • Button
  • Checkbox
  • Color picker
  • Copy button
  • Icon tooltip
  • Inline code
  • Input
  • Hint
  • Kbd
  • Loader
  • Native select
  • Progress bar
  • Progress ring
  • Radio
  • Select
  • Status dot
  • Switch
  • Text link
  • Textarea
  • Tooltip
  • Truncate
Molecules
  • Accordion
  • Activity chart
  • AI elements
  • Alert
  • Button group
  • Card
  • Code block
  • Combobox trigger
  • Command
  • Content table
  • Context switcher
  • Dropdown menu
  • Empty state
  • Field
  • Field group
  • Filter chip
  • Flow
  • Heading
  • Icon picker
  • Icon flow card
  • Metric card
  • Modal
  • Modal confirmation
  • Pagination
  • Popover
  • Scroll area
  • Sidebar
  • Table
  • Tabs
  • Toggle group
LibraryPublished release