Source: https://everyrole.dev/blog/accessible-form-errors

# Accessible form error messages: the markup and six tests

Accessible form error messages are tied to their field, announced, and say the fix. The markup, six tests to run in a browser, and the WCAG rules behind them.

Nov 22, 2026  updated Nov 30, 2026  7 min read  by the EveryRole team

Accessible form error messages do three jobs. Each one is tied to its field, so software knows which field it is about. It is announced when it appears, so someone who can’t see the screen learns that something went wrong. And it says what to do, in words, without relying on colour.

You can test all three in a few minutes with a browser and no special tool. That is most of this post. First, what good looks like.

![A form error before and after. Before: the message "Invalid input" at the top, a red border, a placeholder standing in for a label. After: a Name label, and under the field "Enter a name, up to 60 characters", with the note kept](https://everyrole.dev/s/blog/accessible-form-errors/before-after.webp)

Nothing about the second form is harder to build. It was just decided on purpose.

## The markup that does it

For one field with an error, this is all it takes:

```
<label for="name">Name</label>
<input id="name" name="name" required maxlength="60"
       aria-invalid="true" aria-describedby="name-error">
<p id="name-error">Enter a name, up to 60 characters.</p>
```

Three ties are made here:

- `for="name"` ties the label to the field. A screen reader says “Name” when the field takes focus, and a click on the word puts the cursor in the field.
- `aria-describedby="name-error"` ties the error to the field. When focus lands there, the reader says the label and then the error.
- `aria-invalid="true"` says the field is in an error state, for people who can’t see the red border.

Add `aria-invalid` and the error paragraph when the error happens, and remove them when it is fixed. The `aria-describedby` tie can stay all the time if the paragraph is simply empty when there is no error.

## How to test accessible form error messages

Send your form wrong (empty is the quickest), then run these six.

**1. Click the label.** Click the word “Name”, not the box. The cursor should land in the field. If it doesn’t, the label isn’t tied, and everything else in this list is built on sand. This also catches forms where a placeholder is doing a label’s job: there is nothing to click.

**2. Is the error tied to its field?** Open the developer tools, select the field, and look at its accessibility panel. The field’s description should be the error text. Or paste this in the console to list every `aria-describedby` that points at nothing:

```
[...document.querySelectorAll('[aria-describedby]')].filter(e =>
  !e.getAttribute('aria-describedby').split(' ')
    .every(id => document.getElementById(id)))
```

An empty list is a pass. Broken ties creep in after a refactor: an id is renamed on one side only, and nothing visible changes.

**3. Is it announced?** After the failed send, where is the keyboard focus? Press Tab once and see where you are. There are two good designs. Focus moves to the first field with an error. Or focus moves to a summary at the top that lists the errors as links to their fields. The third design, an error region marked `role="alert"`, is fine for a single message. The failing case: errors appear, focus stays on the button, and nothing was said.

Then listen once. Turn on the screen reader your computer already has (VoiceOver on a Mac, Narrator on Windows) or the free NVDA, send the form wrong, and hear what it says. If it says nothing about an error, this test fails, whatever the markup claims.

**4. Does it say what to do?** Read the message aloud without looking at the form. “Invalid input” tells you nothing. “Enter a name, up to 60 characters” tells you the field and the fix. If your message would fit any field, it is too vague for this one.

**5. Take the colour away.** Is there anything besides red? Text counts. An icon with a text alternative counts. A red border alone is invisible to some people with colour blindness and to every screen reader.

**6. Fix it and send again.** The error should go away, in the markup as well as on screen. A stale `aria-invalid="true"` on a field that is now fine keeps announcing an error that no longer exists. We have a whole post on this second half: [wrong, then right](https://everyrole.dev/blog/wrong-then-right-test).

## The WCAG rules behind the six tests

If someone asks which part of WCAG 2.2 a test covers, this is the map. All are level A except 3.3.3 and 4.1.3, which are AA.

| Test | Success criterion |
| --- | --- |
| 1. Click the label | 1.3.1 Info and Relationships, 3.3.2 Labels or Instructions |
| 2. Tied to its field | 1.3.1 Info and Relationships |
| 3. Announced | 4.1.3 Status Messages, 3.3.1 Error Identification |
| 4. Says what to do | 3.3.1 Error Identification, 3.3.3 Error Suggestion |
| 5. Not colour alone | 1.4.1 Use of Color |
| 6. Fixed and sent again | None by name. It is where the other five break after a fix |

## What about the browser’s own messages?

If you mark a field `required` and do nothing else, the browser stops the send and shows its own bubble (“Please fill out this field” in Chrome). That bubble is tied to the field and announced, so it passes more of this list than a hand-made error that skips the ties.

Its limits: you can’t style it, it shows one error at a time, it disappears after a few seconds, and its wording is the browser’s. For a short form it is a reasonable start. Just don’t stop there, because the browser’s check is only the first of two guards.

## The error your server sends

Every form has a second set of error messages: the ones the server sends when something gets past the browser. They are written once and rarely seen again. We wrote about finding them in [the empty form test](https://everyrole.dev/blog/empty-form-test).

Here is our practice app’s. We removed `required` from the name field in the browser’s tools, typed a note, and pressed Create.

![The practice app's answer from the server to an empty name: a page titled New item with one red message, "A name of 1 to 60 characters, please", and no form](https://everyrole.dev/s/blog/accessible-form-errors/message-without-a-field.webp)

The server’s message says what to do. There is no field left to tie it to.

Run the six tests on this page:

- The wording passes test 4. “A name of 1 to 60 characters, please” names the field and the rule.
- It fails the rest by default, because there is no form. No label to click, no field for the error to describe, no focus to move, and the note we typed is gone. The message is a paragraph on an otherwise empty page.

That is what an inaccessible error looks like when it isn’t about colours or ARIA at all. The most accessible thing this page could do is show the form again, with what was typed, and the message under the name field.

## Error message best practices, in short

- One message per field, under the field, tied with `aria-describedby`.
- For long forms, also a summary at the top that links to each field with an error.
- Say the fix. Give the format if there is one (“like name@example.com”).
- Don’t clear the form. Keep everything that was typed, except passwords.
- If the page reloads to show errors, start its title with “Error:”. It is the first thing a screen reader says.
- Don’t validate while the person is still typing their first character. Wait until they leave the field.
- Don’t blame. “Enter a name” reads better than “You failed to enter a name”.

## What a tool can check here, and what EveryRole does

Of the six tests, code can decide the first for certain: whether every field has a label. It is one of the checks on our [accessibility testing checklist](https://everyrole.dev/blog/accessibility-testing-checklist). EveryRole’s page checks do that on every page of your app in a full run, and a placeholder is not counted as a label. A field without one is reported as “A field on this page has no label”.

For the error itself, EveryRole runs the refused cases at each form (empty, and wrong format where a field states one) and shows you the first result: what was typed, beside what the page answered. You say yes once if it is right. After that, code compares every run with that answer, and checks that a refused case saved nothing. If the message changes or disappears, the case shows Result changed and you are asked.

It reads a message tied to its field the way test 2 ties it, and shows it beside that field on the first result. It doesn’t report a broken tie, where the focus went, an error shown by colour alone, or a stale error after the fix. Tests 2, 3, 5 and 6 are still a person’s job.

## Try it on your own app

EveryRole tests your app’s real user journeys for each kind of user, from the live site, and runs them after every deploy. Paste your app’s address to see what it finds.

[Start with your app](https://everyrole.dev/signup) [How it works](https://everyrole.dev/docs#start)

## Keep reading

Accessibility and phones

### [Accessibility testing checklist (WCAG): what code can decide](https://everyrole.dev/blog/accessibility-testing-checklist)

An accessibility testing checklist in two parts: five WCAG checks code can decide on every page after every deploy, and the manual checks that need a person.

Nov 22, 2026  7 min read

Accessibility and phones

### [Keyboard accessibility testing in ten minutes](https://everyrole.dev/blog/keyboard-accessibility-testing)

Keyboard accessibility testing needs no tool. Put the mouse away, press Tab, and check that you can reach everything, see where you are, and never get stuck.

Nov 22, 2026  6 min read

Accessibility and phones

### [Find broken links and dead buttons on your site](https://everyrole.dev/blog/find-broken-links)

How to find broken links on a website you own: ask for each internal link once, slowly, and read the answer. Then the links a checker calls fine that aren’t.

Nov 22, 2026  6 min read
