Validation Message
Introduction
Section titled “Introduction”A standalone field message for controls that AbsoluteUI does not render itself. ValidationMessage shows an error, warning, success, or info message with a tone icon, adds its id to the target’s aria-describedby, and, for errors, sets aria-invalid="true" on the target. AbsoluteUI inputs render the same aui-validation-message markup internally, so standalone and built-in messages look identical.
- Four tonesError, warning, success, and info messages, each with its own icon.
- Linked to the controlAdds itself to the control's description and marks the control invalid for errors.
- Consistent lookUses the same markup as the messages built into AbsoluteUI inputs.
- Safe textMessages are set as text and never parsed as HTML.
Use it for
- Messages for consumer-rendered or third-party controls that should look and behave like AbsoluteUI field messages.
- Non-error field feedback such as an availability check result (success, warning, info).
Use something else for
- AbsoluteUI inputs and Form Field: they render their own messages; use setCustomError() for external errors.
- Form-level or page-level errors: use Error Summary.
- Transient notifications: use a toast.
Anatomy
<div class="aui-validation-message aui-validation-message--error" id=auto [hidden]> (consumer host) <svg class="aui-validation-message__icon aui-icon" aria-hidden="true"> <span class="aui-validation-message__text">Message</span></div><input aria-describedby="... auto" aria-invalid="true"> (target, `for`)Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Validation Message in the Employee profile form showcase
Section titled “Validation Message in the Employee profile form showcase”The part of the Employee profile form showcase that uses Validation Message. 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']);Error message for a consumer-rendered control
Section titled “Error message for a consumer-rendered control”import { ValidationMessage } from '@absoluteui/components/validation-message';import { TextInput } from '@absoluteui/components/text-input';
const inputHost = document.createElement('div');const messageHost = document.createElement('div');document.body.append(inputHost, messageHost);const input = TextInput.create(inputHost, { label: 'Coupon code', name: 'coupon' }).input;// Adds its id to the input's aria-describedby and sets aria-invalid="true" for tone 'error'.const message = ValidationMessage.create(messageHost, { for: input, message: 'Enter a coupon code.' });input.addEventListener('input', () => { if (input.value !== '') message.clear();});Tones for an availability check
Section titled “Tones for an availability check”import { ValidationMessage } from '@absoluteui/components/validation-message';import { TextInput } from '@absoluteui/components/text-input';
const inputHost = document.createElement('div');const messageHost = document.createElement('div');document.body.append(inputHost, messageHost);const input = TextInput.create(inputHost, { label: 'Handle', name: 'handle' }).input;const message = ValidationMessage.create(messageHost, { for: input });
async function check(handle: string, signal: AbortSignal): Promise<void> { message.setMessage('Checking availability…', 'info'); const response = await fetch(`/api/handles/${encodeURIComponent(handle)}`, { signal }); if (response.status === 404) message.setMessage('This handle is available.', 'success'); else if (response.ok) message.setMessage('This handle is taken.', 'error'); else message.setMessage('Availability could not be checked.', 'warning');}
let pending: AbortController | null = null;input.addEventListener('change', () => { pending?.abort(); const controller = new AbortController(); pending = controller; check(input.value, controller.signal).catch(() => { // A newer check aborted this one and owns the message. if (!controller.signal.aborted) message.clear(); });});Custom tone icons
Section titled “Custom tone icons”import { ValidationMessage } from '@absoluteui/components/validation-message';
const messageHost = document.createElement('div');document.body.append(messageHost);ValidationMessage.create(messageHost, { message: 'Saved as draft.', tone: 'info', icons: { info: 'check' } });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 { ValidationMessage } from '@absoluteui/components/validation-message';import '@absoluteui/components/validation-message/style.css';First use
Section titled “First use”import { ValidationMessage } from '@absoluteui/components/validation-message';import '@absoluteui/components/validation-message/style.css';
const input = document.querySelector<HTMLInputElement>('#promo');const host = document.querySelector<HTMLElement>('#promo-message');if (input && host) { const message = ValidationMessage.create(host, { for: input }); input.addEventListener('change', () => { if (input.value === '') message.clear(); else if (/^[A-Z0-9]{6}$/.test(input.value)) message.setMessage('Code applied.', 'success'); else message.setMessage('Enter a 6-character code.', 'error'); });}More usage
import { ValidationMessage } from '@absoluteui/components/validation-message';
const input = document.createElement('input');const messageHost = document.createElement('div');document.body.append(input, messageHost);ValidationMessage.create(messageHost, { for: input, message: 'Enter a coupon code.' });Using Angular? See Validation Message for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”ValidationMessage.create(host: HTMLElement, options?: ValidationMessageOptions): ValidationMessageGlobal configuration key: validationMessage (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
message |
string |
"" |
Message text. Empty hides the message and unlinks the target. |
tone |
'error' | 'warning' | 'success' | 'info' |
"error" |
Visual tone and icon. Only ‘error’ sets aria-invalid on the target. |
for |
HTMLElement | null |
Control described by the message: receives the host id in aria-describedby while a message is shown, and aria-invalid for errors. | |
icons |
Partial<{ error: IconRef; warning: IconRef; success: IconRef; info: IconRef }> |
Icon overrides per tone. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
Consumer host; receives an id if it has none. |
message |
string |
Current message (‘’ when hidden). |
tone |
ValidationMessageTone |
Current tone. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
setMessage(message: string, tone?: ValidationMessageTone): void |
Set the message and optionally the tone. |
clear(): void |
Hide the message and unlink the target. |
update(options: Partial<ValidationMessageOptions>): void |
Merge and apply options; throws before changing anything on an invalid tone or target. |
destroy(): void |
Unlink the target, remove rendering and classes, and unhide the host. |
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-validation-message |
Host (also used by the built-in field error element). |
aui-validation-message--error | --warning | --success | --info |
Tone modifiers. |
aui-validation-message__icon |
Tone icon. |
aui-validation-message__text |
Message text. |
Icon slots
Section titled “Icon slots”| Slot | Default icon |
|---|---|
error |
alert-circle |
warning |
alert-triangle |
success |
check-circle |
info |
info |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-color-error-fg | --aui-color-info-fg | --aui-color-success-fg | --aui-color-warning-fg | --aui-font-family-sans | --aui-font-size-sm | --aui-icon-size-sm | --aui-line-height-normal | --aui-space-1
TypeScript definitions
type ValidationMessageTone = 'error' | 'warning' | 'success' | 'info';interface ValidationMessageIcons { error: IconRef; warning: IconRef; success: IconRef; info: IconRef }interface ValidationMessageOptions { message?: string; tone?: ValidationMessageTone; for?: HTMLElement | null; icons?: Partial<ValidationMessageIcons> }interface ValidationMessageConfig {}Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: Field description referenced by aria-describedby, with aria-invalid on the target for errors (HTML/ARIA).
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 |
|---|---|---|
| None | Any | Not focusable; the message is read with the target when the target is focused. |
| Element | Role |
|---|---|
| host | none (generic container) |
| icon | none (aria-hidden=true) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-describedby |
target | Host id added while a message is shown; other ids are kept |
aria-invalid |
target | “true” while an error-tone message is shown; removed when the tone changes, the message clears, or the target changes, but only if this message set it. An aria-invalid=“true” the consumer set beforehand is never removed |
Not focusable and never moves focus.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| Criterion | Level | Note |
|---|---|---|
| 1.3.1 Info and Relationships | A | |
| 1.4.1 Use of Color | A | |
| 1.4.3 Contrast (Minimum) | AA | |
| 3.3.1 Error Identification | A | |
| 3.3.3 Error Suggestion | AA | |
| 4.1.2 Name, Role, Value | A |
Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- Tones pair color with a distinct icon; the message text must still state the problem.
- Only the error tone marks the target invalid; warning, success, and info are descriptive only.
- The message is not a live region; announce important changes separately if the user is not on the target.
- Screen-reader reading of the description has not yet been manually verified with NVDA, JAWS, and VoiceOver.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/validation-message |
30.6 kB | 10.6 kB | 9.4 kB | 0.3 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| ValidationMessage.update | No dedicated performance test; re-renders icon and text on each update |
Tested scale: Unit tests cover single messages linked to one target.
No listeners or subscriptions. Each update re-renders the icon and text.
Measured run times: Performance.
Details
Section titled “Details”States
hidden (empty message), error, warning, success, info.
State transitions
| From | Trigger | To |
|---|---|---|
| hidden | message set | visible; target described; aria-invalid for error tone |
| error | tone changes to warning/success/info | aria-invalid removed (if this message set it) |
| visible | for changes |
old target unlinked; new target linked |
| visible | clear() or empty message |
hidden; target unlinked |
| any | destroy() |
target unlinked; host emptied and unhidden |
Accessibility notes
- Tones pair color with a distinct icon; the text must still state the problem (WCAG 1.4.1).
- Only the error tone marks the target invalid; the other tones are descriptive only.
- The message is not a live region: it is read when the user reaches the target. Announce important changes separately (for example with
announce()from@absoluteui/utilities) if the user is elsewhere. - Manual screen-reader verification is pending (see Known limitations).
Responsive behavior
Icon and text in a row; long messages wrap anywhere.
Right-to-left
Follows the document direction; the icon sits at the inline start.
Theming
Tone foreground role tokens only; no background. Forced-colors mode uses system text colors, with the icon distinguishing tones.
Global configuration
None. validationMessageConfig is registered with an empty schema, so configureAbsoluteUI({ components: { validationMessage: {} } }) accepts no options.
Component configuration
All options are instance options and dynamic through update().
Icons
icons.error (default alert-circle), icons.warning (alert-triangle), icons.success (check-circle), and icons.info (info).
Security
The message uses textContent and is never parsed as HTML. Do not include raw user input in messages. CSP-safe.
Data handling
No persistence, network access, or telemetry.
Supported data scale
One message per instance, one target per message.
Edge cases
- An empty message hides the host and removes the reference from the target, keeping the other
aria-describedbyids. - Without
for, the message is only visual. - If the target already has
aria-invalid="true"when an error is shown, the message leaves it to the consumer and does not remove it later. destroy()keeps the generated host id.
Errors
| Code | Category | Cause |
|---|---|---|
VALIDATION_MESSAGE_OPTIONS |
configuration | tone is not error, warning, success, or info; or for is not an HTMLElement or null. |
A failed construction or update leaves no rendering or ARIA changes behind.
Known limitations
- Not a live region.
- The icon element is re-created on every update.
- No
locale: the text is consumer-provided. - Screen-reader reading has not yet been manually verified with NVDA, JAWS, and VoiceOver.
Unsupported scenarios
- HTML or links in the message.
- One message describing several targets.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.