component
Checkbox
A choice that's on or off and waits for the form. A 20px box that fills green with a tick, and the words beside it.
Try it
Every variant
Default · Not checked · Not indeterminateDisabled · Not checked · Not indeterminateDefault · Checked · Not indeterminateDisabled · Checked · Not indeterminateDefault · Checked · IndeterminateDisabled · Checked · IndeterminateHover, press or tab to one to see the other 9 states.
import { Checkbox } from 'rost/components/checkbox/Checkbox'
<Checkbox name="vat" checked={vat} onCheckedChange={setVat}>Include VAT</Checkbox> src/components/checkbox/Checkbox.tsx
import { useEffect, useRef, useState, type InputHTMLAttributes, type ReactNode } from 'react'
import './checkbox.css'
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'children'> {
/** The words beside it. Without them, give it an `aria-label`. */
readonly children?: ReactNode
/** Half-ticked: some of a group are ticked. Drawn ticked, with a dash. */
readonly indeterminate?: boolean
/** Called with the new value each time it changes. */
readonly onCheckedChange?: (checked: boolean) => void
}
const b = 'rost-checkbox'
/**
* A choice that's on or off and waits for the form. A real `<input type="checkbox">` inside a
* `<label>`, so forms, Space and screen readers work as they always do.
* Built from contracts/checkbox.contract.yaml.
*/
export function Checkbox({ children, checked, defaultChecked = false, indeterminate = false, onChange, onCheckedChange, className, style, ...rest }: CheckboxProps) {
const [own, setOwn] = useState(defaultChecked)
const on = checked ?? own
const input = useRef<HTMLInputElement>(null)
// The browser's own half-ticked state, which screen readers read as "mixed". It has no attribute.
useEffect(() => { if (input.current) input.current.indeterminate = indeterminate }, [indeterminate])
return (
<label className={[b, (on || indeterminate) && `${b}--checked`, indeterminate && `${b}--indeterminate`, className].filter(Boolean).join(' ')} style={style}>
<input
ref={input}
type="checkbox"
className={`${b}__input`}
checked={on}
onChange={(e) => {
onChange?.(e)
if (checked === undefined) setOwn(e.target.checked)
onCheckedChange?.(e.target.checked)
}}
{...rest}
/>
<span className={`${b}__box`} aria-hidden="true">
<span className={`${b}__check`} />
<span className={`${b}__focus-ring`} />
</span>
{children != null && <span className={`${b}__label`}>{children}</span>}
</label>
)
}
The source for everything on this page: contracts/checkbox.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: checkbox
name: Checkbox
kind: component
status: review
summary: A choice that's on or off and waits for the form. A 20px box that fills green with a tick, and the words beside it.
category: selection
related: [ switch, radio, chips ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "733:64"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=733-64
extractedAt: "2026-11-16"
extractedBy: hand
frozenAt: "2026-11-16"
props:
checked: { type: boolean, default: false, notes: "Ticked or not. It's the input's own `checked`, so a form sends it. In React, controlled with `checked` or left to itself with `defaultChecked`." }
indeterminate: { type: boolean, default: false, notes: "Half-ticked: the box stands for a group where only some are ticked, like a table's \"select all\" when some rows are picked. It draws the ticked look with a dash instead of the tick, and the input says \"mixed\" to screen readers. What a press does is the caller's: usually it ticks them all." }
children: { type: slot, notes: "The label, beside the box. Leave it out only when something else names it (`aria-label`)." }
states: [ Default, Hover, Pressed, Focus, Disabled ]
stateSelectors:
Focus: ":has(> .rost-checkbox__input:focus-visible)"
Disabled: ":has(> .rost-checkbox__input:disabled)"
elements:
root:
notes: "A `<label>` around the input, the box and the words, so a press anywhere on it counts. Hover and press come from the label."
styles:
display: { value: inline-flex, assert: false }
align-items: { value: center }
gap: { token: spacing/gap/small, value: 8px }
vertical-align: { value: middle, assert: false }
position: { value: relative, assert: false }
cursor: { value: pointer, assert: false }
input:
notes: "The real `<input type=\"checkbox\">`, there for the keyboard, forms and screen readers, and hidden from sight. The box draws what it says."
styles:
position: { value: absolute, assert: false }
width: { value: 1px, assert: false }
height: { value: 1px, assert: false }
opacity: { value: "0", assert: false }
pointer-events: { value: none, assert: false }
box:
notes: "The 20px square, the size of a small icon, with 4px corners. Empty it's the page's colour inside a field's edge. Ticked it's filled with the primary green."
styles:
position: { value: relative, assert: false }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
border-radius: { token: spacing/radius/xsmall, value: 4px }
outline-style: { value: solid, assert: false, notes: "Drawn inside the box, like Switch's track, so it can be seen against the page." }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the box." }
check:
notes: "The tick, drawn with `icon-check.svg` as a mask in the colour of a primary button's label, 2px in from the box's edge."
styles:
position: { value: absolute }
inset: { token: spacing/gap/3xsmall, value: 2px }
mask-image: { value: "url(./icon-check.svg)", assert: false }
mask-size: { value: 100% 100%, assert: false }
mask-repeat: { value: no-repeat, assert: false }
pointer-events: { value: none, assert: false }
focus-ring:
notes: "Around the box, keeping its shape."
styles:
display: { value: none, assert: false }
position: { value: absolute }
inset: { value: "calc(-1 * var(--spacing-gap-2xsmall))", untokenised: "Composed from a token: the ring sits spacing/gap/2xsmall outside the box." }
border-style: { value: solid }
border-width: { token: spacing/outline/medium, value: 2px }
border-radius: { token: spacing/radius/small, value: 8px }
pointer-events: { value: none, assert: false }
label:
notes: "The words. Paragraph type, in the colour SwitchField's label has. It doesn't change when it's ticked: the box says that."
styles:
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/regular, value: "400" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
color: { token: checkbox/label, value: "#d3d9d5" }
variants:
- when: { checked: false }
elements:
check:
display: { value: none, assert: false }
- when: { checked: true }
elements:
box:
outline-color: { token: checkbox/on/edge, value: "#00d669", notes: "The fill's own green in dark. In light it's a dark green, because the bright fill is 1.9:1 on white, the way Switch's track does it." }
check:
display: { value: block, assert: false }
- when: { indeterminate: true }
elements:
check:
mask-image: { value: "url(./icon-minus.svg)", assert: false, notes: "Rost's minus icon in place of the tick. Everything else is the ticked look, so a half-ticked box has a ticked one's colours in every state." }
- when: { state: Focus }
elements:
focus-ring:
display: { value: block, assert: false }
- when: { state: Disabled }
elements:
root:
opacity: { token: opacity/gentle, value: "0.24" }
cursor: { value: default, assert: false }
- when: { state: Default, checked: false }
figmaNode: "733:3"
elements:
box:
background: { token: checkbox/off/default/box, value: "#060805" }
outline-color: { token: checkbox/off/default/edge, value: "#747573" }
- when: { state: Hover, checked: false }
figmaNode: "733:9"
elements:
box:
background: { token: checkbox/off/hover/box, value: "#171717" }
outline-color: { token: checkbox/off/hover/edge, value: "#999999" }
- when: { state: Pressed, checked: false }
figmaNode: "733:15"
elements:
box:
background: { token: checkbox/off/pressed/box, value: "#171717" }
outline-color: { token: checkbox/off/pressed/edge, value: "#999999" }
- when: { state: Focus, checked: false }
figmaNode: "733:21"
elements:
box:
background: { token: checkbox/off/focus/box, value: "#060805" }
outline-color: { token: checkbox/off/focus/edge, value: "#747573" }
focus-ring:
border-color: { token: checkbox/off/focus/focus-ring, value: "#999" }
- when: { state: Disabled, checked: false }
figmaNode: "733:27"
elements:
box:
background: { token: checkbox/off/disabled/box, value: "#060805" }
outline-color: { token: checkbox/off/disabled/edge, value: "#747573" }
- when: { state: Default, checked: true }
figmaNode: "733:33"
elements:
box:
background: { token: checkbox/on/default/box, value: "#00d669" }
check:
background: { token: checkbox/on/default/check, value: "#060805" }
- when: { state: Hover, checked: true }
figmaNode: "733:39"
elements:
box:
background: { token: checkbox/on/hover/box, value: "#00b450" }
check:
background: { token: checkbox/on/hover/check, value: "#060805" }
- when: { state: Pressed, checked: true }
figmaNode: "733:45"
elements:
box:
background: { token: checkbox/on/pressed/box, value: "#00913a" }
check:
background: { token: checkbox/on/pressed/check, value: "#060805" }
- when: { state: Focus, checked: true }
figmaNode: "733:51"
elements:
box:
background: { token: checkbox/on/focus/box, value: "#00d669" }
check:
background: { token: checkbox/on/focus/check, value: "#060805" }
focus-ring:
border-color: { token: checkbox/on/focus/focus-ring, value: "#b6ffda" }
- when: { state: Disabled, checked: true }
figmaNode: "733:57"
elements:
box:
background: { token: checkbox/on/disabled/box, value: "#00d669" }
check:
background: { token: checkbox/on/disabled/check, value: "#060805" }
guidance:
status: proposed
use:
- title: Choices that wait for Save
text: "Settings in a form that only count when it's sent: what goes on an invoice, which months to include."
show: state=Default, checked=True, indeterminate=False
- title: Agreeing to something
text: "One box before a button, like \"I've checked these figures\"."
avoid:
- title: A setting that works at once
text: "If it changes something the moment you flip it, that's **Switch**."
- title: One choice out of several
text: "When picking one rules out the others, that's **Radio**."
behaviour: |-
Empty is a field's edge around the page colour. Ticked fills with the primary green, with a dark tick, the way a primary button looks. Hover, press and focus come from the browser. Disabled fades the whole row, words too.
Half-ticked (`indeterminate`) is the ticked look with a dash, for a box that stands for a group where only some are ticked, like a table's "select all".
accessibility:
element: "A real `<input type=\"checkbox\">` inside a `<label>`. The input is hidden from sight, not from screen readers."
name: "The words beside it, through the label. Without words, give it an `aria-label`."
keyboard: "Tab reaches it. Space ticks and unticks it."
focus: "`focus-ring` around the box, on `:focus-visible`."
colour: "Ticked isn't only green: the tick is there too. The empty box's edge is 4.3:1 on the dark page. Ticked, the edge is the fill's green in dark and a dark green in light, so the box stands out at 3:1 or more on both."
content: "Say what's true when it's ticked, in sentence case: \"Include VAT\", not \"VAT: yes/no\"."
Install
npx github:Runceanu/rost add checkbox It lands in src/rost/checkbox/, with what it needs and its contract. Install has the rest.
When to use
Choices that wait for Save
Settings in a form that only count when it's sent: what goes on an invoice, which months to include.
Agreeing to something
One box before a button, like "I've checked these figures".
When not to use
A setting that works at once
If it changes something the moment you flip it, that's Switch.
One choice out of several
When picking one rules out the others, that's Radio.
Behaviour
Empty is a field's edge around the page colour. Ticked fills with the primary green, with a dark tick, the way a primary button looks. Hover, press and focus come from the browser. Disabled fades the whole row, words too.
Half-ticked (indeterminate) is the ticked look with a dash, for a box that stands for a group where only some are ticked, like a table's "select all".
Accessibility
- Element
A real
<input type="checkbox">inside a<label>. The input is hidden from sight, not from screen readers. - Name
The words beside it, through the label. Without words, give it an
aria-label. - Keyboard
Tab reaches it. Space ticks and unticks it.
- Focus
focus-ringaround the box, on:focus-visible. - Colour
Ticked isn't only green: the tick is there too. The empty box's edge is 4.3:1 on the dark page. Ticked, the edge is the fill's green in dark and a dark green in light, so the box stands out at 3:1 or more on both.
Content
Say what's true when it's ticked, in sentence case: "Include VAT", not "VAT: yes/no".
Props
| Prop | Type | Values | Default |
|---|---|---|---|
checked | boolean | | false |
indeterminate | boolean | | false |
children | slot | | |
States: Default, Hover, Pressed, Focus, Disabled.
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap8pxspacing/gap/small
displayinline-flex · align-itemscenter · vertical-alignmiddle · positionrelative · cursorpointer
input
positionabsolute · width1px · height1px · opacity0 · pointer-eventsnone
box
-
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
border-radius4pxspacing/radius/xsmall -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the box.
positionrelative · flex-shrink0 · outline-stylesolid
check
-
inset2pxspacing/gap/3xsmall
positionabsolute · mask-imageurl(./icon-check.svg) · mask-size100% 100% · mask-repeatno-repeat · pointer-eventsnone
focus-ring
-
border-stylesolidno token yet -
border-width2pxspacing/outline/medium -
border-radius8pxspacing/radius/small
displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone
label
-
font-family'General Sans Variable'font-family/base -
font-weight400typography/paragraph/font-weight/regular -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing -
color#d3d9d5checkbox/label
Changes by variant
11 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.
Follows state
Checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
check.backgroundcheckbox/on/… | default/check #060805 | hover/check #060805 | pressed/check #060805 | focus/check #060805 | disabled/check #060805 |
Follows checked
All but Indeterminate
| Property | Not checked | Checked |
|---|---|---|
check.display | none | block |
Focus
| Property | Not checked | Checked |
|---|---|---|
focus-ring.border-colorcheckbox/… | off/focus/focus-ring #999 | on/focus/focus-ring #b6ffda |
Follows state and checked
Not checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
box.backgroundcheckbox/off/… | default/box #060805 | hover/box #171717 | pressed/box #171717 | focus/box #060805 | disabled/box #060805 |
box.outline-colorcheckbox/off/… | default/edge #747573 | hover/edge #999999 | pressed/edge #999999 | focus/edge #747573 | disabled/edge #747573 |
Checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
box.backgroundcheckbox/on/… | default/box #00d669 | hover/box #00b450 | pressed/box #00913a | focus/box #00d669 | disabled/box #00d669 |
box.outline-colorcheckbox/on/… | edge #00d669 | edge #00d669 | edge #00d669 | edge #00d669 | edge #00d669 |
Only in some variants
These don't change: they're just set in some variants and not others.
Indeterminate
-
check.mask-imageurl(./icon-minus.svg)Figma frame size
Focus
-
focus-ring.displayblocklayout
Disabled
-
root.cursordefaultFigma frame size -
root.opacity0.24opacity/gentle