Sub topic 11
Designing forms with labels, hints and errors
Forms are where accessibility failures cost users the most. A missed label or a vague error can stop someone from paying, applying, or signing in. This chapter assumes you know the basic HTML form elements, the WCAG principles (perceivable, operable, understandable, robust), and how to read a wireframe's headings and landmarks. It covers what to specify in a wireframe so that each form field reaches developers with its label, hint, and error behavior already decided.
Why forms need decisions at the wireframe stage
Three things decide whether a form works for people using screen readers, voice control, magnification, or only a keyboard:
- The label, which names the field.
- The hint, which tells people what to enter before they enter it.
- The error message, which tells people what went wrong and how to fix it.
If a wireframe shows only boxes with gray placeholder text, a developer has to guess all three. Guesses tend to produce placeholder-only labels, generic errors such as "Invalid input", and errors shown only in red. Deciding these items early costs a line of annotation. Fixing them after visual design and build costs rework in layout, copy, and code.
Several WCAG 2.2 success criteria apply here:
| Criterion | Level | What it asks for |
|---|---|---|
| 1.3.1 Info and Relationships | A | Labels, groups, and errors are programmatically tied to the fields they describe |
| 1.3.5 Identify Input Purpose | AA | Fields that collect personal data declare their purpose (for example with `autocomplete`) |
| 2.4.6 Headings and Labels | AA | Labels describe the purpose of the field |
| 3.3.1 Error Identification | A | Errors are identified and described in text |
| 3.3.2 Labels or Instructions | A | Fields have labels or instructions |
| 3.3.3 Error Suggestion | AA | When a fix is known, the error suggests it |
| 3.3.4 Error Prevention (Legal, Financial, Data) | AA | Important submissions can be reviewed, corrected, or reversed |
| 3.3.7 Redundant Entry | A | Information already entered is not requested again in the same process |
| 4.1.3 Status Messages | AA | Status messages can be announced without moving focus |
Labels
A label is visible text that names a field. Specify these rules in the wireframe:
- Every field has a persistent visible label. Place it above the field or beside it, and keep it on screen while the user types.
- Do not use placeholder text as the label. Placeholder text disappears when typing starts, so users lose the field's name and cannot review their entries. It is also often rendered in low-contrast gray.
- The visible text is the accessible name. If a field shows "Email address", the programmatic name should contain that same text. Voice control users say what they see on screen (WCAG 2.5.3 Label in Name, level A).
- Group related fields. Radio buttons, checkboxes, and multi-part fields such as a date of birth need a group name. Draw a group heading in the wireframe and annotate it as a
fieldsetwith alegend.
Label placement affects other parts of the design. Labels above fields reflow better on narrow screens and when text is zoomed. Labels to the left of a field can force horizontal scrolling at 320 CSS pixels wide, which conflicts with reflow requirements.
Required and optional fields
Mark the convention once, near the top of the form, and apply it consistently. For example: "All fields are required unless marked optional." If you use an asterisk, explain it in text before the first field. Do not mark required fields with color alone. Annotate the programmatic state too, using the required attribute.
Hints
A hint is short text that explains format or purpose before the user makes a mistake. Good candidates are password rules, date formats, and the reason you ask for something sensitive such as a phone number.
- Put the hint between the label and the field, or directly under the label, so it reads in order.
- Keep the hint visible. Do not hide it in a tooltip that appears only on hover, because keyboard and touch users may never see it.
- Tie the hint to the input programmatically so a screen reader announces it with the field.
Use autocomplete tokens for fields that collect the user's own details. This meets WCAG 1.3.5 and helps people who have difficulty typing or remembering information.
Errors
An error message has to be found, understood, and acted on. Specify five things for every error pattern in the wireframe.
- Location. Show the message next to the field it concerns, usually directly above or below the input.
- Text. Say what is wrong and how to fix it. "Enter an email address in the format [email protected]" works. "Invalid input" does not.
- More than color. A red border alone fails WCAG 1.4.1 Use of Color. Add an icon and the message text, and check that each cue has enough contrast (3:1 for the icon and border, 4.5:1 for the text).
- Programmatic link. The field is marked invalid and points to its message.
- Announcement and focus. Decide what happens on submit.
Where focus goes after a failed submit
Two common patterns work. Pick one and annotate it.
- Error summary. Show a summary at the top of the page that lists every problem, each item linking to its field. Move focus to the summary's heading. This works well for long forms because the user gets the full picture at once.
- Focus the first invalid field. Move focus straight to the first field with an error. This suits short forms with one or two inputs.
Whichever you choose, make sure a screen reader user hears that errors exist. If focus does not move, use a live region so the announcement does not depend on sight.
When to validate
Validating on every keystroke often shows "invalid" before the user has finished typing. Validate on blur (when the user leaves the field) or on submit. Annotate this in the wireframe, because developers will otherwise choose by default.
Putting it in code
The wireframe annotations should translate directly into markup like this. The label is persistent, the hint and the error are both tied to the input through aria-describedby, and autocomplete declares the input's purpose.
<label for="email">Email address</label>
<p id="email-hint">We will send your receipt here.</p>
<input id="email" name="email" type="email" autocomplete="email"
required aria-invalid="true"
aria-describedby="email-hint email-error">
<p id="email-error">Enter an email address in the format [email protected].</p>Screen readers typically announce the label, then the field type, then the descriptions in the order listed in aria-describedby. The aria-invalid="true" attribute should be present only when the field has an error. Setting it on a pristine field makes every field sound broken.
A matching error summary for a failed submission looks like this:
<div id="error-summary" role="alert" tabindex="-1">
<h2 id="error-summary-title">There is a problem</h2>
<ul>
<li><a href="#email">Enter an email address in the format [email protected].</a></li>
<li><a href="#postcode">Enter a postcode, for example SW1A 1AA.</a></li>
</ul>
</div>The tabindex="-1" lets a script move focus to the summary without adding it to the normal tab order. Because each link points to a field ID, a user can jump straight to the problem.
Common errors
- Placeholder as label. The field has no name once typing begins. Fix it with a persistent visible label.
- Error text separated from the field. A message at the bottom of the page is far from the field and invisible to magnifier users. Place it next to the field and repeat it in a summary.
- Generic messages. "Error" or "Invalid" fails Error Suggestion. Name the field and the fix.
- Hint hidden in a tooltip. Keyboard and touch users miss it. Keep it visible.
- Disabled submit button as validation. A button that stays inactive gives no explanation. Let the user submit and then explain what is wrong.
- Timeouts without warning. If a session can expire, annotate a warning and a way to extend it (WCAG 2.2.1 Timing Adjustable, level A).
- Asking twice. Do not require users to retype data they already gave, such as a billing address that matches the shipping address. Offer a checkbox or prefill the fields (3.3.7).
Annotating a form in the wireframe
A good annotation is short, testable, and tied to one element. For the email field above, the wireframe note might read:
- Visible label "Email address", above the field, always shown.
- Hint "We will send your receipt here." under the label.
- Required.
autocomplete="email". - Error shows on submit. Text: "Enter an email address in the format [email protected]." Icon plus red border plus message.
- On failed submit, focus moves to the error summary heading.
Flow of a failed submission
Checking your design
Before moving on from low fidelity, run these checks on the wireframe:
- Can you name every field without looking at placeholder text?
- Does every error state exist as its own wireframe frame, not only the happy path?
- Is each error written out in real words, not "error text here"?
- Does the annotation say where focus goes after submit?
- Are required, optional, and format rules written in text?
Exercise
A signup wireframe shows a text box with gray placeholder text "Phone number" and no other text. After a failed submit, the box gets a red border. List three changes to specify in the annotations.
Show answer
(1) Add a persistent visible label "Phone number" above the field, and use the placeholder only for an optional example if at all. (2) Add error text next to the field that says what is wrong and how to fix it, for example "Enter a phone number with 10 digits", plus an icon, so the error does not rely on red alone. (3) Annotate the programmatic link: aria-invalid="true" and aria-describedby pointing to the error text, with focus moving to an error summary or the field on submit. Adding autocomplete="tel" and a visible format hint are also valid.
Exercise
Why does a hint that appears only in a hover tooltip fail some users, and what should the wireframe show instead?
Show answer
Keyboard users and touch users may never trigger a hover, and screen readers may not announce the tooltip. The wireframe should show the hint as always-visible text near the label, tied to the input with aria-describedby.