Checkbox
Introduction
Section titled “Introduction”A single on/off choice submitted with a form. Checkbox renders a native <input type="checkbox"> restyled with appearance: none, so the native input stays the focus target, the hit target, and the source of truth for checked and mixed state. It adds a label, required indicator, help text, and a localized validation message. The check and minus marks are icons layered over the box.
- Native checkboxA restyled native checkbox stays the focus target and the source of truth.
- Mixed stateAn indeterminate state for parent choices that are partly selected.
- Required consentRequired and custom checks with localized messages, for terms and confirmations.
- Help textA description under the label, linked for screen readers.
Use it for
- A single independent yes/no choice that is submitted with a form, such as accepting terms or opting into a newsletter.
- A “select all” parent that shows a mixed state when only some children are selected.
- A choice that must be confirmed before continuing (required).
Use something else for
- Several related choices: use Checkbox Group.
- One choice from a set of mutually exclusive options: use Radio Group.
- A setting that takes effect immediately: use Switch.
Anatomy
<div class="aui-field aui-checkbox" data-aui-control> (consumer host) <div class="aui-checkbox__row"> <span class="aui-checkbox__box"> <input type="checkbox" class="aui-checkbox__input"> <span class="aui-checkbox__mark aui-checkbox__mark--checked"><svg aria-hidden="true"></span> <span class="aui-checkbox__mark aui-checkbox__mark--indeterminate"><svg aria-hidden="true"></span> </span> <label class="aui-field__label aui-checkbox__label" for=input>Label<span class="aui-field__required" aria-hidden="true">*</span></label> </div> <div class="aui-field__description"> (optional) <div class="aui-field__error aui-validation-message"> (when shown)</div>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Checkbox in the Employee profile form showcase
Section titled “Checkbox in the Employee profile form showcase”The part of the Employee profile form showcase that uses Checkbox. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Forms showcase: an employee profile form that uses every form control together,// with constraint validation, a cross-field rule, the error summary, reset, and live options.import { Button } from '@absoluteui/components/button';import { Checkbox } from '@absoluteui/components/checkbox';import { CheckboxGroup } from '@absoluteui/components/checkbox-group';import { Combobox } from '@absoluteui/components/combobox';import { Fieldset } from '@absoluteui/components/fieldset';import { Form, type FormSubmitDetail } from '@absoluteui/components/form';import { FormField } from '@absoluteui/components/form-field';import { MultiSelect } from '@absoluteui/components/multi-select';import { NumberInput } from '@absoluteui/components/number-input';import { RadioGroup } from '@absoluteui/components/radio-group';import { Select } from '@absoluteui/components/select';import { Slider } from '@absoluteui/components/slider';import { Switch } from '@absoluteui/components/switch';import { TextInput } from '@absoluteui/components/text-input';import { Textarea } from '@absoluteui/components/textarea';import { ValidationMessage } from '@absoluteui/components/validation-message';import { action, annotate, choice, createShowcase, hostIn, toggle } from './kit.js';
const sc = createShowcase({ title: 'Employee profile', description: 'Every form control in one form: required fields, formats, ranges, a cross-field rule, and an error summary on submit.',});
const form = document.createElement('form');form.className = 'sc-form';form.noValidate = true;sc.stage.append(form);
// Each fieldset declares its controls, so a component's focus view shows its own group.const fieldset = (legend: string, description?: string): HTMLFieldSetElement => { const fs = document.createElement('fieldset'); form.append(fs); Fieldset.enhance(fs, { legend, ...(description ? { description } : {}) }); return fs;};
const DEPARTMENTS = [ { value: 'eng', label: 'Engineering' }, { value: 'fin', label: 'Finance' }, { value: 'hr', label: 'People' }, { value: 'ops', label: 'Operations' }, { value: 'sales', label: 'Sales' },];const MANAGERS = ['Ada Kowalski', 'Bruno Silva', 'Chen Wei', 'Divya Nair', 'Emeka Obi', 'Farah Haddad', 'Grace Liu', 'Hiro Tanaka'].map((name) => ({ value: name.toLowerCase().replace(/\s+/g, '-'), label: name }));const SKILLS = ['Accessibility', 'Angular', 'Data analysis', 'Design systems', 'Finance', 'Negotiation', 'People management', 'TypeScript'].map((s) => ({ value: s.toLowerCase().replace(/\s+/g, '-'), label: s }));
// Personal details.const personal = annotate(fieldset('Personal details'), ['form', 'error-summary', 'fieldset', 'text-input', 'textarea', 'form-field']);const name = TextInput.create(hostIn(personal), { label: 'Full name', name: 'name', required: true, minLength: 2, autocomplete: 'name' });const email = TextInput.create(hostIn(personal), { label: 'Work email', name: 'email', type: 'email', required: true, autocomplete: 'email', description: 'Used for sign-in and notifications.' });const phone = TextInput.create(hostIn(personal), { label: 'Phone', name: 'phone', type: 'tel', inputMode: 'tel', pattern: '[+]?[0-9 ]{7,20}', description: 'Digits and spaces, with an optional leading +.' });const bio = Textarea.create(hostIn(personal), { label: 'About', name: 'bio', maxLength: 280, showCounter: true, rows: 3, resize: 'vertical' });
// A native control labelled and validated by Form Field.const badge = document.createElement('input');badge.name = 'badge';badge.inputMode = 'numeric';badge.pattern = '[0-9]{6}';FormField.create(hostIn(personal), { label: 'Badge number', control: badge, description: 'Six digits printed on your badge.' });
// Role.const role = annotate(fieldset('Role'), ['form', 'error-summary', 'validation-message', 'fieldset', 'select', 'combobox', 'radio-group', 'number-input', 'slider', 'multi-select']);const department = Select.create(hostIn(role), { label: 'Department', name: 'department', options: DEPARTMENTS, placeholder: 'Choose a department', required: true });const manager = Combobox.create(hostIn(role), { label: 'Manager', name: 'manager', options: MANAGERS, placeholder: 'Type a name', description: 'Search by first or last name.' });const type = RadioGroup.create(hostIn(role), { label: 'Employment type', name: 'type', orientation: 'horizontal', required: true, options: [{ value: 'full', label: 'Full time' }, { value: 'part', label: 'Part time' }, { value: 'contract', label: 'Contractor' }] });const salary = NumberInput.create(hostIn(role), { label: 'Annual salary', name: 'salary', min: 10000, max: 500000, step: 1000, format: { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } });const hours = Slider.create(hostIn(role), { label: 'Weekly hours', name: 'hours', min: 8, max: 48, step: 1, largeStep: 4, value: 40, marks: [{ value: 20, label: '20' }, { value: 40, label: '40' }], showValue: true });const skills = MultiSelect.create(hostIn(role), { label: 'Skills', name: 'skills', options: SKILLS, maxSelected: 5, description: 'Up to five.' });
// Preferences.const prefs = annotate(fieldset('Preferences', 'You can change these later in settings.'), ['form', 'error-summary', 'fieldset', 'checkbox-group', 'switch', 'checkbox']);const benefits = CheckboxGroup.create(hostIn(prefs), { label: 'Benefits', name: 'benefits', orientation: 'horizontal', options: [{ value: 'health', label: 'Health' }, { value: 'pension', label: 'Pension' }, { value: 'transit', label: 'Transit pass' }, { value: 'gym', label: 'Gym' }] });const remote = Switch.create(hostIn(prefs), { label: 'Works remotely', name: 'remote' });const terms = Checkbox.create(hostIn(prefs), { label: 'I confirm these details are correct', name: 'terms', required: true });
// A standalone validation message for a rule that is not tied to one control.const actions = annotate(hostIn(form), ['form', 'error-summary', 'validation-message']);actions.className = 'sc-form__actions';const hint = ValidationMessage.create(hostIn(actions), { tone: 'info', message: 'Part-time employees work at most 32 hours per week.' });
const buttons = hostIn(actions);buttons.className = 'sc-form__buttons';const submit = Button.create({ text: 'Save profile', variant: 'primary', type: 'submit' }, document);const reset = Button.create({ text: 'Reset', variant: 'secondary', type: 'reset' }, document);buttons.append(submit.element, reset.element);
const formController = Form.create(form, { summaryTitle: 'Fix these fields to save the profile', rules: [ { fields: ['type', 'hours'], validate: (values) => (values.type === 'part' && Number(values.hours) > 32 ? 'Part-time employees work at most 32 hours per week.' : null), }, ],});
form.addEventListener('aui-submit', (e) => { const { values } = (e as CustomEvent<FormSubmitDetail>).detail; submit.setLoading(true); // A save takes a moment; the button stays busy and focusable meanwhile. setTimeout(() => { submit.setLoading(false); hint.update({ tone: 'success', message: `Saved the profile of ${typeof values.name === 'string' ? values.name : 'the employee'}.` }); }, 600);});form.addEventListener('aui-reset', () => { hint.update({ tone: 'info', message: 'Part-time employees work at most 32 hours per week.' });});
sc.listen(form, ['aui-submit', 'aui-invalid', 'aui-reset'], 'form');for (const [label, host] of [ ['name', name.host], ['email', email.host], ['department', department.host], ['manager', manager.host], ['type', type.host], ['salary', salary.host], ['hours', hours.host], ['skills', skills.host], ['benefits', benefits.host], ['remote', remote.host], ['terms', terms.host],] as const) { sc.listen(host, ['aui-change'], label);}
// Options.const all = [name, email, phone, bio, department, manager, type, salary, hours, skills, benefits, remote, terms];toggle(sc, 'Disabled', false, (disabled) => { for (const c of all) c.update({ disabled }); badge.disabled = disabled; submit.update({ disabled });});toggle(sc, 'Read-only', false, (readOnly) => { for (const c of [name, email, phone, bio, department, manager, salary, skills]) c.update({ readOnly }); badge.readOnly = readOnly;});choice( sc, 'Validate', [ { value: 'blur', label: 'When leaving a field' }, { value: 'input', label: 'While typing' }, { value: 'submit', label: 'On submit only' }, ], 'blur', (timing) => { for (const c of [name, email, phone, bio, department, type, salary, benefits, terms]) c.update({ validationTiming: timing }); },);action(sc, 'Fill sample data', () => { name.setValue('Ada Lovelace'); email.setValue('ada@example.com'); phone.setValue('+44 20 7946 0000'); bio.setValue('Writes the first programs and reviews every pull request.'); badge.value = '204816'; department.setValue('eng'); manager.setValue('chen-wei'); type.setValue('full'); salary.setValue(86000); hours.setValue(38); skills.setValue(['typescript', 'accessibility']); benefits.setValue(['health', 'pension']); remote.setChecked(true); terms.setChecked(true); sc.log('sample data filled');});action(sc, 'Submit empty', () => { formController.reset(); formController.submit();}, ['form', 'error-summary']);Required terms checkbox
Section titled “Required terms checkbox”import { Checkbox } from '@absoluteui/components/checkbox';
const host = document.createElement('div');document.body.append(host);const terms = Checkbox.create(host, { label: 'I accept the terms and conditions', name: 'terms', value: 'accepted', required: true });host.addEventListener('aui-change', () => { host.dataset.valid = String(terms.validity.valid);});Select-all parent with a mixed state
Section titled “Select-all parent with a mixed state”import { Checkbox } from '@absoluteui/components/checkbox';
const host = document.createElement('div');document.body.append(host);const all = Checkbox.create(host, { label: 'Select all files', indeterminate: true });function syncSelectAll(selected: number, total: number): void { all.setChecked(selected === total, selected > 0 && selected < total);}syncSelectAll(3, 5);Show messages on first change (Mode B)
Section titled “Show messages on first change (Mode B)”import { configureAbsoluteUI } from '@absoluteui/core';
configureAbsoluteUI({ components: { checkbox: { validationTiming: 'input' } } });Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Checkbox } from '@absoluteui/components/checkbox';import '@absoluteui/components/checkbox/style.css';First use
Section titled “First use”import { Checkbox } from '@absoluteui/components/checkbox';import '@absoluteui/components/checkbox/style.css';
const host = document.querySelector<HTMLElement>('#newsletter');if (host) { const newsletter = Checkbox.create(host, { label: 'Send me the monthly newsletter', name: 'newsletter', value: 'monthly' }); host.addEventListener('aui-change', () => { host.dataset.subscribed = String(newsletter.checked); });}More usage
import { Checkbox } from '@absoluteui/components/checkbox';
const host = document.createElement('div');document.body.append(host);Checkbox.create(host, { label: 'I accept the terms and conditions', name: 'terms', value: 'accepted', required: true });Using Angular? See Checkbox for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Checkbox.create(host: HTMLElement, options: CheckboxOptions): CheckboxGlobal configuration key: checkbox (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
label |
string |
Visible label and accessible name; clicking it toggles the checkbox. Required. | |
hideLabel |
boolean |
false |
Visually hide the label; it remains the accessible name. |
checked |
boolean |
false |
Initial checked state; also restored by reset(). |
indeterminate |
boolean |
false |
Mixed state (aria-checked=mixed via the native property). Cleared when the user toggles. |
value |
string |
"on" |
Submitted value when checked. |
name |
string |
Form field name. | |
description |
string |
Help text referenced by aria-describedby. | |
required |
boolean |
false |
The box must be checked; shows the required indicator. |
disabled |
boolean |
false |
Disables the checkbox. |
validate |
(checked: boolean) => string | null |
Consumer validation; return a message to mark the state invalid. | |
icons |
Partial<{ checked: IconRef; indeterminate: IconRef; error: IconRef }> |
Icon slot overrides. | |
validationTiming |
'blur' | 'input' | 'submit' |
"blur" |
When validation messages first appear; afterwards they update live. Globally configurable. |
locale |
string |
"en-US" |
Message locale. Globally configurable. Inherited from common configuration. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
Consumer host; its children are owned by the component. |
input |
HTMLInputElement |
The native checkbox. |
checked |
boolean |
Current checked state. |
indeterminate |
boolean |
Current mixed state. |
value |
string |
Submitted value when checked. |
name |
string | null |
Form field name. |
label |
string |
Label text. |
disabled |
boolean |
Disabled state. |
validity |
FieldValidity |
{ valid, error, message }; computed on every change. |
dirty |
boolean |
Checked or mixed state differs from the initial state. |
touched |
boolean |
Focus has left the control at least once. |
options |
Readonly<CheckboxOptions> |
Current instance options. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
setChecked(checked: boolean, indeterminate?: boolean): void |
Programmatic state (no events); clears the mixed state unless given and clears an external custom error. |
update(options: Partial<CheckboxOptions>): void |
Merge and apply options. |
reportValidity(): boolean |
Show messages now and return validity. |
setCustomError(message: string | null): void |
External error; cleared when the user toggles. |
getFormValue(): string | null |
value when checked, otherwise null. |
focus(): void |
Focus the checkbox. |
reset(): void |
Restore the initial checked and mixed state and clear dirty/touched/submitted state. |
destroy(): void |
Remove rendering, listeners, registration, and subscriptions. |
Events
Section titled “Events”| Event | Detail | Bubbles | Cancelable | Description |
|---|---|---|---|---|
aui-change |
{ checked: boolean; value: string; validity: FieldValidity } |
Yes | No | The user toggled the checkbox. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-field aui-checkbox |
Host. |
aui-checkbox--invalid | --disabled |
State modifiers on the host. |
aui-field__label | __required | __description | __error |
Shared field chrome. |
aui-checkbox__row |
Box and label row. |
aui-checkbox__box |
Positioning wrapper for the input and marks. |
aui-checkbox__input |
Native checkbox, restyled as the box. |
aui-checkbox__mark | __mark--checked | __mark--indeterminate |
Decorative check and minus marks. |
aui-checkbox__label |
The label (also aui-field__label). |
Icon slots
Section titled “Icon slots”| Slot | Default icon |
|---|---|
checked |
check |
indeterminate |
minus |
error |
alert-circle |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-border-width | --aui-color-border | --aui-color-border-strong | --aui-color-disabled-bg | --aui-color-error-fg | --aui-color-focus-ring | --aui-color-on-primary | --aui-color-primary | --aui-color-surface | --aui-color-text | --aui-color-text-disabled | --aui-color-text-muted | --aui-duration-fast | --aui-easing-standard | --aui-focus-ring-offset | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-md | --aui-font-size-sm | --aui-font-weight-medium | --aui-font-weight-regular | --aui-icon-size-md | --aui-icon-size-sm | --aui-line-height-normal | --aui-line-height-tight | --aui-radius-sm | --aui-space-1 | --aui-space-2 | --aui-touch-target-min
TypeScript definitions
type ValidationTiming = 'blur' | 'input' | 'submit';interface FieldValidity { readonly valid: boolean; readonly error: ValidationErrorCode | null; readonly message: string }interface CheckboxIcons { checked: IconRef; indeterminate: IconRef; error: IconRef }interface CheckboxChangeDetail { checked: boolean; value: string; validity: FieldValidity }Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: Native <input type=“checkbox”> with a <label for> association (HTML; WAI-ARIA APG Checkbox, dual- and tri-state).
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| Tab / Shift+Tab | Any | Moves focus to and from the checkbox. |
| Space | Checkbox focused | Toggles the checkbox (native). A mixed checkbox becomes checked. |
| Element | Role |
|---|---|
| input | checkbox (native); aria-checked=mixed via the indeterminate property |
| marks and icons | none (aria-hidden=true) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-describedby |
input | Help text and visible error message ids |
aria-invalid |
input | “true” only while an error message is shown |
The native input is the focus target and shows a color-focus-ring outline on :focus-visible, offset from the box.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- The required asterisk is aria-hidden; required state is conveyed by the native required attribute.
- Checked and mixed states are shown by a check or minus shape, not only by the fill color.
- Clicking the label toggles the checkbox, extending the hit target.
- Errors appear after the first blur by default; when focus leaves because of a pointer press, the message appears after the pointer is released so the click is not displaced.
- Screen-reader announcement of the mixed state and error message has not yet been manually verified with NVDA, JAWS, and VoiceOver.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/checkbox |
39.4 kB | 13.4 kB | 11.9 kB | 1.0 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Checkbox.create, per instance (1,000 instances) | < 1 ms average in headless Chromium (target; not yet covered by the performance test) |
Tested scale: Unit-tested per instance; not yet included in the 1,000-instance performance test.
Two listeners per instance (change, focusout), one document-level pointer tracker shared by all fields, and one configuration subscription. Target: under 1 ms per Checkbox.create; not yet covered by the performance test.
Measured run times: Performance.
Details
Section titled “Details”States
default, hover, focus-visible, checked, indeterminate (mixed), disabled, disabled checked, required, invalid (message shown).
State transitions
| From | Trigger | To |
|---|---|---|
| unchecked | click, label click, or Space | checked; aui-change |
| checked | click, label click, or Space | unchecked; aui-change |
| indeterminate | user toggle | checked (native), mixed cleared |
| any | focus leaves the host | touched; messages shown (blur timing) |
| any | reportValidity() |
submitted; messages shown for every timing |
| invalid (custom error) | user toggles | custom error cleared |
| any | reset() |
initial state; pristine, untouched |
Accessibility notes
- The required asterisk is
aria-hidden; the nativerequiredattribute conveys the state. - Checked and mixed states use a check or minus shape, not only color (WCAG 1.4.1).
- The label is clickable, so the target is the whole row (WCAG 2.5.8); the row is at least
touch-target-mintall. - Errors appear after the first blur by default. When focus leaves because of a pointer press, the message appears after the pointer is released so the pending click is not displaced.
- Manual screen-reader verification is pending (see Known limitations).
Responsive behavior
The box is fixed-size; the label wraps beside it. Help text and messages align with the label.
Right-to-left
Logical properties throughout: the box is at the inline start and help text is indented from the inline start. The check mark is not mirrored.
Theming
Colors come from role tokens only. High-contrast themes widen border-width. In forced-colors mode the box uses Canvas/CanvasText, checked uses Highlight with a HighlightText mark, and disabled uses GrayText, with forced-color-adjust: none so the custom box stays visible.
Global configuration
configureAbsoluteUI({ components: { checkbox: { validationTiming: 'input' } } });Changes apply to existing instances immediately.
Component configuration
Instance options override global and theme defaults. All options are dynamic.
Icons
icons.checked (default check), icons.indeterminate (default minus), and icons.error (default alert-circle).
Security
All text uses textContent. Validation messages never include the value. CSP-safe: no inline styles or HTML strings.
Data handling
No persistence, network access, or telemetry. The native input submits name=value when checked and name is set.
Supported data scale
One value per instance. Not yet included in the 1,000-instance performance test.
Edge cases
- Toggling a mixed checkbox makes it checked and clears the mixed state (native behavior).
setChecked(true)clears the mixed state;setChecked(false, true)shows mixed.- A mixed checkbox that is not checked submits nothing.
Errors
| Code | Category | Cause |
|---|---|---|
CHECKBOX_OPTIONS |
configuration | Missing label, non-string value, or non-function validate. |
Validation (validity.error) |
validation | value-missing (“Check this box to continue.”), custom. |
A failed construction leaves no rendering, listeners, or subscriptions behind.
Known limitations
- The mixed state is presentational and never submitted.
- The box alone is 1.25rem; the 24px target is met by the row and label.
- Screen-reader behavior of the mixed state and messages has not yet been manually verified with NVDA, JAWS, and VoiceOver.
Unsupported scenarios
- HTML (for example links) inside the label.
- Read-only checkboxes.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.