Skip to content
fa
Search Frontend Atlas
Search questions and concepts across the handbook.
UI Engineering & Machine Codingintermediate10 min read

How should a production form communicate validation errors?

Combine native constraints, server validation, field-level association, focus management, and accessible summaries.

A form is not finished when it can detect an invalid value. People need to know which field needs attention, what went wrong and how to correct it. Validation also has timing: showing errors on every keystroke can be noisy, while waiting until submission can leave users with a long list of surprises.

A form is not finished when it can detect an invalid value. People need to know which field needs attention, what went wrong and how to correct it. Validation also has timing: showing errors on every keystroke can be noisy, while waiting until submission can leave users with a long list of surprises.

The quick version

Validate at the appropriate boundary, associate each field with its help and error text, expose invalid state, and provide a clear submission summary. Server validation remains authoritative for business rules.

Build the mental model

Use stable IDs with aria-describedby; set aria-invalid only when invalid. On failed submit, focus an error summary or the first invalid field according to the interaction model. Do not rely on color or placeholder text alone.

See it in code

<label for="email">Email</label>
<input id="email" type="email" aria-invalid="true" aria-describedby="email-error" />
<p id="email-error">Enter a valid email address.</p>

Where it gets tricky

A field error should be programmatically associated with its control and announced at a useful time. A form-level error summary helps users understand multiple failures and navigate to each field. Do not clear the user’s input after a server rejection. Validate again on the server because client validation can be bypassed or become stale.

A common misunderstanding

Client-side validation is not a security boundary, and announcing every keystroke error can be noisy.

What this changes in an application

Choose validation timing carefully: often validate on submit, then revalidate touched fields. Preserve entered data after server errors.

Questions worth exploring next

  • How would you announce async username validation?
  • Why is required not sufficient?

References and next steps

  • WAI form notifications — primary or authoritative documentation for the underlying behavior.
  • MDN Web Docs — use the relevant API reference for adjacent browser details.