Checkbox
<gui-checkbox> is a checkbox for a yes or no choice. It renders a native
<input type="checkbox"> inside its label, so clicking the text checks it too.
import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxBasic() { return <GuiCheckbox label="Send me the monthly newsletter" />;}import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-basic', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox label="Send me the monthly newsletter"></gui-checkbox> `,})export class CheckboxBasicComponent {}<script setup lang="ts">import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';</script>
<template> <gui-checkbox label="Send me the monthly newsletter"></gui-checkbox></template>import { LitElement, html } from 'lit';import { customElement } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-basic')export class CheckboxBasic extends LitElement { protected override createRenderRoot() { return this; }
override render() { return html` <gui-checkbox label="Send me the monthly newsletter"></gui-checkbox> `; }}<gui-checkbox label="Send me the monthly newsletter"></gui-checkbox>The element’s entry point is @golemui/gui-components/checkbox, which registers <gui-checkbox>
and nothing else. To install the package and load the stylesheet, see
Installation.
The @golemui/gui-components/react components have typed props and an on* prop for each event. React 18 or later.
import { useState } from 'react';import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function NewsletterField() { const [newsletter, setNewsletter] = useState(false);
return ( <GuiCheckbox label="Send me the monthly newsletter" name="newsletter" value={newsletter} onGuiChange={(event) => setNewsletter(event.detail.value ?? false)} /> );}Add CUSTOM_ELEMENTS_SCHEMA to the component that uses the tags, and the stylesheet to styles in angular.json.
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import type { GuiEventMap, GuiCheckboxEvents } from '@golemui/gui-components';import '@golemui/gui-components/checkbox';
type ChangeEvent = GuiEventMap<typeof GuiCheckboxEvents>['gui-change'];
@Component({ selector: 'app-newsletter-field', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox label="Send me the monthly newsletter" name="newsletter" [value]="newsletter" (gui-change)="onChange($event)" ></gui-checkbox> `,})export class NewsletterFieldComponent { newsletter = false;
onChange(event: Event) { this.newsletter = (event as ChangeEvent).detail.value ?? false; }}"styles": ["node_modules/@golemui/gui-components/lib/styles/index.css"]Tell Vue's compiler that gui-* tags are custom elements, and add the typings once for typed props and @gui-* handlers.
<script setup lang="ts">import { ref } from 'vue';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
const newsletter = ref(false);</script>
<template> <gui-checkbox label="Send me the monthly newsletter" name="newsletter" :value="newsletter" @gui-change="newsletter = $event.detail.value ?? false" /></template>vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('gui-') } },});import type {} from '@golemui/gui-components/vue';The page's stylesheet styles the gui-* elements, so it only reaches them outside a shadow root. Render the host component into the light DOM too, as below, or load the stylesheet into its shadow root.
import { LitElement, html } from 'lit';import { customElement, state } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('newsletter-field')export class NewsletterField extends LitElement { @state() private newsletter = false;
protected override createRenderRoot() { return this; }
override render() { return html` <gui-checkbox label="Send me the monthly newsletter" name="newsletter" .value=${this.newsletter} @gui-change=${(event: CustomEvent) => (this.newsletter = event.detail.value)} ></gui-checkbox> `; }}With any bundler, such as Vite. Import the element once, anywhere, and use the tag in your markup.
<gui-checkbox label="Send me the monthly newsletter" name="newsletter"></gui-checkbox>
<script type="module" src="./main.js"></script>import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
const element = document.querySelector('gui-checkbox');
element.addEventListener('gui-change', (event) => { console.log(event.detail.value);});Properties
| Property | Type | Default | Description |
|---|---|---|---|
localeId
attribute locale-id | string | 'en' | BCP 47 locale for formatting and parsing, such as en-US or es. |
value | boolean | – | Whether it is checked. As an attribute, value checks it and value="false" does not. |
checkboxPosition
attribute checkbox-position | 'left' | 'right' | 'left' | Side of the label the checkbox is on. |
uid | string | – | The id of the element's control. The ids of its label, hint and errors derive from it. Optional: when it is not set, the element generates one from its tag name and a page-wide counter, e.g. gui-textinput-3. Generated ids depend on creation order, so a server-rendered element must set uid or its ids will not match after hydration. |
idPrefix
attribute id-prefix | string | – | Goes in front of every DOM id the element renders, so two elements with the same uid in different forms render different ids. GolemUI Forms sets it to the form's formName. Only ids and the references to them (for, aria-describedby…) take it: data-cy attributes and event details keep the bare uid. |
domId read-only, no attribute | string | – | The id of the element's control: uid, behind idPrefix when it is set. |
Form control properties
Every field has these, from the base class of the form controls.
| Property | Type | Default | Description |
|---|---|---|---|
name | string | – | The name the value is submitted under. Without it the element stays out of its form. Reflected, like a native control's: the form reads a single value's name from the attribute. |
label | string | – | The visible label, which also names the control for assistive technology. Without one the control has no accessible name; the date, time, range, tags and file fields warn about it in development builds. |
hint | string | – | Help text shown under the label and announced as the control's description. |
errors | string[] | [] | Error messages to show, typically from your own validation. They show as soon as they are set, unless touched is false. |
touched | boolean | – | Whether the user has interacted with the control. Leave it unset unless you validate on interaction: false holds errors back until it becomes true. |
required | boolean | false | The control needs a value: it is marked as required and, with a name, blocks submission. |
readOnly
attribute readonly | boolean | – | The value can be read and focused but not changed. |
disabled | boolean | – | Disabled by its own attribute or by a disabled <fieldset> around it. Setting the property sets the attribute, like a native control's. |
form read-only, no attribute | HTMLFormElement | null | – | The <form> the element belongs to, if any. |
validity read-only, no attribute | ValidityState | – | The element's validity, like a native control's. |
validationMessage read-only, no attribute | string | – | The message the browser shows for an invalid value. |
Methods
| Method | Description |
|---|---|
checkValidity(): boolean | – |
reportValidity(): boolean | – |
Events
Every event bubbles and is composed, so you can listen on any ancestor.
| Event | Description |
|---|---|
gui-input | The user changed the value. detail.value is the new value. |
gui-change | The user committed the value. detail.value is the committed value. |
gui-blur | Focus left the control. |
Examples
Section titled “Examples”Checked
Section titled “Checked”The value is true or false. As an attribute, value checks the box and value="false"
leaves it unchecked. From JavaScript, set the value property to true or false.
import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxChecked() { return <GuiCheckbox label="Remember me on this device" value />;}import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-checked', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox label="Remember me on this device" value></gui-checkbox> `,})export class CheckboxCheckedComponent {}<script setup lang="ts">import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';</script>
<template> <gui-checkbox label="Remember me on this device" :value="true"></gui-checkbox></template>import { LitElement, html } from 'lit';import { customElement } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-checked')export class CheckboxChecked extends LitElement { protected override createRenderRoot() { return this; }
override render() { return html` <gui-checkbox label="Remember me on this device" value></gui-checkbox> `; }}<gui-checkbox label="Remember me on this device" value></gui-checkbox>hint shows under the label. Screen readers read it as the checkbox’s description.
import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxHint() { return ( <GuiCheckbox label="Share anonymous usage data" hint="It helps us fix crashes. We never collect your files." /> );}import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-hint', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox label="Share anonymous usage data" hint="It helps us fix crashes. We never collect your files." ></gui-checkbox> `,})export class CheckboxHintComponent {}<script setup lang="ts">import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';</script>
<template> <gui-checkbox label="Share anonymous usage data" hint="It helps us fix crashes. We never collect your files." ></gui-checkbox></template>import { LitElement, html } from 'lit';import { customElement } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-hint')export class CheckboxHint extends LitElement { protected override createRenderRoot() { return this; }
override render() { return html` <gui-checkbox label="Share anonymous usage data" hint="It helps us fix crashes. We never collect your files." ></gui-checkbox> `; }}<gui-checkbox label="Share anonymous usage data" hint="It helps us fix crashes. We never collect your files."></gui-checkbox>Checkbox position
Section titled “Checkbox position”The checkbox sits before the label. checkbox-position="right" puts it after the label.
import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxPosition() { return ( <GuiCheckbox label="Email me when someone replies" checkboxPosition="right" /> );}import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-position', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox label="Email me when someone replies" checkbox-position="right" ></gui-checkbox> `,})export class CheckboxPositionComponent {}<script setup lang="ts">import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';</script>
<template> <gui-checkbox label="Email me when someone replies" checkbox-position="right" ></gui-checkbox></template>import { LitElement, html } from 'lit';import { customElement } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-position')export class CheckboxPosition extends LitElement { protected override createRenderRoot() { return this; }
override render() { return html` <gui-checkbox label="Email me when someone replies" checkbox-position="right" ></gui-checkbox> `; }}<gui-checkbox label="Email me when someone replies" checkbox-position="right"></gui-checkbox>Disabled and read-only
Section titled “Disabled and read-only”A disabled checkbox can’t be focused or changed, and a form doesn’t submit it. A readonly
checkbox can be focused but clicks and Space don’t change it, and a form submits its
value.
import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxDisabledReadonly() { return ( <div className="gui-grid gui-grid--row"> <div className="gui-grid__cell"> <GuiCheckbox label="Two-factor sign-in" value disabled /> </div> <div className="gui-grid__cell"> <GuiCheckbox label="Admin access" value readOnly /> </div> </div> );}import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-disabled-readonly', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <div class="gui-grid gui-grid--row"> <div class="gui-grid__cell"> <gui-checkbox label="Two-factor sign-in" value disabled></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Admin access" value readonly></gui-checkbox> </div> </div> `,})export class CheckboxDisabledReadonlyComponent {}<script setup lang="ts">import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';</script>
<template> <div class="gui-grid gui-grid--row"> <div class="gui-grid__cell"> <gui-checkbox label="Two-factor sign-in" :value="true" :disabled="true" ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Admin access" :value="true" :readOnly="true" ></gui-checkbox> </div> </div></template>import { LitElement, html } from 'lit';import { customElement } from 'lit/decorators.js';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-disabled-readonly')export class CheckboxDisabledReadonly extends LitElement { protected override createRenderRoot() { return this; }
override render() { return html` <div class="gui-grid gui-grid--row"> <div class="gui-grid__cell"> <gui-checkbox label="Two-factor sign-in" value disabled ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Admin access" value readonly></gui-checkbox> </div> </div> `; }}<div class="gui-grid gui-grid--row"> <div class="gui-grid__cell"> <gui-checkbox label="Two-factor sign-in" value disabled></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Admin access" value readonly></gui-checkbox> </div></div>Errors
Section titled “Errors”errors takes a list of messages from your own validation, and shows them under the checkbox.
Set the errors property from a gui-change listener to validate as the user works. Check the
box, then uncheck it.
import { useState } from 'react';import { GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxValidation() { const [errors, setErrors] = useState<string[]>([]);
return ( <GuiCheckbox id="terms-check" label="I accept the terms of service" errors={errors} onGuiChange={(event) => setErrors( event.detail.value ? [] : ['Accept the terms to create your account.'], ) } /> );}import { Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';import type { GuiCheckboxEvents, GuiEventMap } from '@golemui/gui-components';import '@golemui/gui-components/checkbox';
type CheckboxEvent<K extends keyof typeof GuiCheckboxEvents> = GuiEventMap< typeof GuiCheckboxEvents>[K];
@Component({ selector: 'app-checkbox-validation', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <gui-checkbox id="terms-check" label="I accept the terms of service" [errors]="errors()" (gui-change)="onChange($event)" ></gui-checkbox> `,})export class CheckboxValidationComponent { errors = signal<string[]>([]);
onChange(event: Event) { const { value } = (event as CheckboxEvent<'gui-change'>).detail; this.errors.set(value ? [] : ['Accept the terms to create your account.']); }}<script setup lang="ts">import { ref } from 'vue';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
const errors = ref<string[]>([]);
function onChange(accepted: boolean | undefined) { errors.value = accepted ? [] : ['Accept the terms to create your account.'];}</script>
<template> <gui-checkbox id="terms-check" label="I accept the terms of service" :errors.prop="errors" @gui-change="onChange($event.detail.value)" ></gui-checkbox></template>import { LitElement, html } from 'lit';import { customElement, state } from 'lit/decorators.js';import type { GuiCheckboxEvents, GuiEventMap } from '@golemui/gui-components';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
type CheckboxEvent<K extends keyof typeof GuiCheckboxEvents> = GuiEventMap< typeof GuiCheckboxEvents>[K];
@customElement('checkbox-validation')export class CheckboxValidation extends LitElement { @state() private errors: string[] = [];
protected override createRenderRoot() { return this; }
private onChange(event: CheckboxEvent<'gui-change'>) { this.errors = event.detail.value ? [] : ['Accept the terms to create your account.']; }
override render() { return html` <gui-checkbox id="terms-check" label="I accept the terms of service" .errors=${this.errors} @gui-change=${this.onChange} ></gui-checkbox> `; }}<gui-checkbox id="terms-check" label="I accept the terms of service"></gui-checkbox>
<script type="module"> const terms = document.querySelector('#terms-check');
terms.addEventListener('gui-change', (event) => { terms.errors = event.detail.value ? [] : ['Accept the terms to create your account.']; });</script>In a form
Section titled “In a form”With a name, a checked <gui-checkbox> submits on under that name, like a native checkbox,
and an unchecked one submits nothing. required blocks the submit until the box is checked.
Submit the form below, then check the first box and submit again.
import { useState, type SubmitEvent } from 'react';import { GuiButton, GuiCheckbox } from '@golemui/gui-components/react';import '@golemui/gui-components/index.css';
export function CheckboxNativeForm() { const [result, setResult] = useState('');
const onSubmit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); const data = Object.fromEntries(new FormData(event.currentTarget)); setResult(`Submitted ${JSON.stringify(data)}`); };
return ( <form id="signup" onSubmit={onSubmit}> <div className="gui-grid"> <div className="gui-grid__cell"> <GuiCheckbox label="I accept the terms of service" name="terms" required /> </div> <div className="gui-grid__cell"> <GuiCheckbox label="Send me product news" name="news" /> </div> <div className="gui-grid__cell"> <GuiButton type="submit" label="Create account" /> </div> </div> <p id="signup-result" role="status"> {result} </p> </form> );}import { Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';import '@golemui/gui-components/button';import '@golemui/gui-components/checkbox';
@Component({ selector: 'app-checkbox-native-form', schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <form id="signup" #form (submit)="onSubmit($event, form)"> <div class="gui-grid"> <div class="gui-grid__cell"> <gui-checkbox label="I accept the terms of service" name="terms" required ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Send me product news" name="news"></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-button type="submit" label="Create account"></gui-button> </div> </div> <p id="signup-result" role="status">{{ result() }}</p> </form> `,})export class CheckboxNativeFormComponent { result = signal('');
onSubmit(event: SubmitEvent, form: HTMLFormElement) { event.preventDefault(); const data = Object.fromEntries(new FormData(form)); this.result.set(`Submitted ${JSON.stringify(data)}`); }}<script setup lang="ts">import { ref } from 'vue';import '@golemui/gui-components/button';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
const result = ref('');
function onSubmit(event: SubmitEvent) { if (!(event.currentTarget instanceof HTMLFormElement)) return; const data = Object.fromEntries(new FormData(event.currentTarget)); result.value = `Submitted ${JSON.stringify(data)}`;}</script>
<template> <form id="signup" @submit.prevent="onSubmit"> <div class="gui-grid"> <div class="gui-grid__cell"> <gui-checkbox label="I accept the terms of service" name="terms" :required="true" ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Send me product news" name="news"></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-button type="submit" label="Create account"></gui-button> </div> </div> <p id="signup-result" role="status">{{ result }}</p> </form></template>import { LitElement, html } from 'lit';import { customElement, query, state } from 'lit/decorators.js';import '@golemui/gui-components/button';import '@golemui/gui-components/checkbox';import '@golemui/gui-components/index.css';
@customElement('checkbox-native-form')export class CheckboxNativeForm extends LitElement { @query('#signup') private form!: HTMLFormElement; @state() private result = '';
protected override createRenderRoot() { return this; }
private onSubmit(event: SubmitEvent) { event.preventDefault(); const data = Object.fromEntries(new FormData(this.form)); this.result = `Submitted ${JSON.stringify(data)}`; }
override render() { return html` <form id="signup" @submit=${this.onSubmit}> <div class="gui-grid"> <div class="gui-grid__cell"> <gui-checkbox label="I accept the terms of service" name="terms" required ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Send me product news" name="news" ></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-button type="submit" label="Create account"></gui-button> </div> </div> <p id="signup-result" role="status">${this.result}</p> </form> `; }}<form id="signup"> <div class="gui-grid"> <div class="gui-grid__cell"> <gui-checkbox label="I accept the terms of service" name="terms" required></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-checkbox label="Send me product news" name="news"></gui-checkbox> </div> <div class="gui-grid__cell"> <gui-button type="submit" label="Create account"></gui-button> </div> </div> <p id="signup-result" role="status"></p></form>
<script type="module"> const form = document.querySelector('#signup');
form.addEventListener('submit', (event) => { event.preventDefault(); const data = Object.fromEntries(new FormData(form)); document.querySelector('#signup-result').textContent = `Submitted ${JSON.stringify(data)}`; });</script>How the elements submit, validate and reset is in Native forms.
Styling
Section titled “Styling”Anatomy
Section titled “Anatomy”<gui-checkbox> renders into the light DOM, so you can style every part with plain CSS. The label
wraps the checkbox and its text, and the hint and the errors follow it:
<gui-checkbox class="gui-field"> <label class="gui-label" for="terms" id="terms_label"> <div class="gui-widget gui-widget--horizontal"> <input type="checkbox" id="terms" aria-describedby="terms_hint" aria-invalid="true" aria-errormessage="terms_errors" aria-required="true" /> </div> <span class="gui-label__container"> <span class="gui-label__text"> I accept the terms<span aria-hidden="true"> *</span> </span> </span> </label> <div class="gui-widget-hint"> <span id="terms_hint">You can read them first.</span> <div class="gui-validator" id="terms_errors" role="alert"> <div class="gui-validator__error">Accept the terms to continue.</div> </div> </div></gui-checkbox>| Class | Part |
|---|---|
gui-field | The element itself. Lines its parts up with the fields next to it in a gui-grid row. |
gui-checkbox--right | On the element with checkbox-position="right". |
gui-label | The label, with the checkbox and the text. |
gui-widget | The box around the checkbox. |
gui-widget--horizontal | On the box: lays it out in a row. |
gui-label__container | The wrapper of the label text. |
gui-label__text | The label text and the required marker. |
gui-widget-hint | The hint, and the errors after it. It is always there; the hint text has the hint’s id. |
gui-validator | The errors container. It is always there, so the alert role announces new errors. |
gui-validator__error | One error message. |
The ids derive from uid, or from a generated id such as gui-checkbox-3 when you don’t set one.
Select by class or by tag, not by id.
Tokens
Section titled “Tokens”The checkbox reads these design tokens. Set them on :root to change every checkbox, or on any
element to change the checkboxes inside it:
| Token | What it styles |
|---|---|
--gui-bg-surface | The box’s background. |
--gui-border-default | The box’s border. |
--gui-radius-sm | The box’s corner radius. |
--gui-intent-primary | The tick. |
--gui-text-default | The label text. |
--gui-font-family | The font. |
--gui-font-sm | The text size of the label. |
--gui-font-xs | The text size of the hint and the errors. |
--gui-text-secondary | The hint. |
--gui-border-focus | The box’s border while focused. |
--gui-shadow-focus | The focus ring. |
--gui-intent-error | The box’s border and the messages when there are errors. |
--gui-shadow-focus-error | The focus ring when there are errors. |
--gui-space-1 | The space above the errors. |
/* A green tick and rounder boxes. */:root { --gui-intent-primary: #2f7d4f; --gui-radius-sm: 4px;}To restyle beyond the tokens, see Overriding styles; for dark mode and the Clay theme, see Themes and dark mode.
Accessibility
Section titled “Accessibility”- Name. The
labelnames the checkbox. The native<label>wraps it, so a click on the text checks it too. Without a label the checkbox has no accessible name. - Description. The
hintis the checkbox’s description, througharia-describedby. - Errors. While errors show, the checkbox has
aria-invalid="true"and points at them witharia-errormessage, and screen readers announce new errors as they appear. - Required.
requiredsetsaria-required; the visual marker is hidden from screen readers. - Read-only.
readonlysetsaria-readonly. The checkbox stays in the tab order.
| Key | Action |
|---|---|
| Tab | Moves focus to the checkbox, and away from it. |
| Space | Checks or unchecks it, and fires gui-change. |
What every element shares, such as translating the browser messages, is in Accessibility.