Checkbox
One or many independent on or off choices, usually sent with a form.
In Accessible first
See it live
npm run storybookWhen to use it
In Accessible first: Many choices, each with a large target.
- Use it when: Agreeing, picking many, optional extras; the choice waits for the form.
- Not when: Exactly one of a short set (radio group), or a setting that applies at once (switch).
Instead:
- Radio group: One choice only.
- Switch: Applies at once.
- Select: Many options in a compact list.
Words
- Use common words. Explain any term you must use.
- One idea per sentence. Put the action first.
- Never blame the person.
- Use: Continue, Change, Start, You. Avoid: Invalid, Utilise, Submit, Error code.
The labels components use, from the voice tokens:
content.action.commit: Continuecontent.action.cancel: Go backcontent.action.destroy: Deletecontent.action.retry: Try againcontent.action.empty-action: Start a new application
See Voice and tone for the whole voice.
Accessibility and keyboard
| Keyboard | What happens | Not |
|---|---|---|
| undefined | Space checks and unchecks. | undefined |
Test before you ship:
- Each checkbox has a visible label that is part of the hit area. undefined
Use it in code
npx open-ds add checkbox
The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.
Tokens it reads
Checkbox reads 11 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Checkbox's tokens to change Checkbox alone.
Accessible first decides what changes when you switch theme. Here a switch changes colors only, so the marked rows differ between light and dark; everything else holds steady.
| Part | Its token and the semantic it aliases | Value |
|---|---|---|
| Shared | ||
| Button focus ring Changes with theme on focus | component.button.focus-ringcolor.border.focusvar(--button-focus-ring) | Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8 |
| Input background Changes with theme | component.input.backgroundcolor.surface.defaultvar(--input-background) | Lightgray.light.0:#FFFFFFDarkgray.dark.50:#141414 |
| Control checked Changes with theme when on | component.control.checkedcolor.action.primaryvar(--control-checked) | Lightblue.light.600:#0B4FC0Darkblue.dark.600:#8AB4F8 |
| Control track Changes with theme | component.control.trackcolor.border.strongvar(--control-track) | Lightgray.light.500:#595959Darkgray.dark.500:#949494 |
| Control thumb Changes with theme when on | component.control.thumbcolor.surface.defaultvar(--control-thumb) | Lightgray.light.0:#FFFFFFDarkgray.dark.50:#141414 |
| Control radius | component.control.radiusradius.badgevar(--control-radius) | radius.4:0.25rem |
| Checkbox | ||
| Size | component.checkbox.sizesize.iconvar(--checkbox-size) | size.20:1.25rem |
| Border width | component.checkbox.border-widthborder-width.defaultvar(--checkbox-border-width) | border-width.2:2px |
| Focus on focus | component.checkbox.focusborder-width.focusvar(--checkbox-focus) | border-width.3:3px |
| Disabled when disabled | component.checkbox.disabledopacity.disabledvar(--checkbox-disabled) | opacity.50:0.5 |
| Canvas Changes with theme on focus | component.checkbox.canvascolor.surface.canvasvar(--checkbox-canvas) | Lightgray.light.50:#F7F7F7Darkgray.dark.0:#0A0A0A |