Sub topic 11
Designing Forms with Labels, Hints and Errors
Assume you know basic HTML, CSS, and common form controls. You should also be able to read a wireframe and identify its interactive elements.
A form is accessible when people can understand what each field asks for, provide a value, and recover from mistakes. Treat labels, hints, and errors as part of the form's structure, not as visual decoration added later.
Give every field a persistent label
A label names a field and remains visible while the user fills it in. Placeholder text is not a label because it disappears when typing and may have weak contrast.
In a wireframe, show the label above or beside its control. Record the label's exact wording. Connect the label to the field in HTML with matching for and id values.
<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-describedby="email-hint"
>The autocomplete value lets browsers and assistive technologies offer the right saved information. Use familiar, specific labels such as “Date of birth” instead of “Details.”
Add useful hints and instructions
A hint explains a constraint before the user makes an error. For example, a password field might say, “Use 12 or more characters.” Keep the hint close to the field and associate it with aria-describedby.
Do not put essential instructions only at the top of a long form. Users may enter fields out of order, and screen reader users may navigate directly to a control. Repeat important requirements near the relevant field.
Group related controls with a visible legend. A group of payment options, for example, needs one question such as “How would you like to pay?” followed by its choices.
Design clear, recoverable errors
An error should identify the field, explain what went wrong, and state how to fix it. “Invalid input” is not enough. Use “Enter an email address in the format [email protected].”
Show errors beside their fields. For long forms, also provide an error summary near the top with links to the affected fields. On submission, move focus to the summary or the first invalid field so keyboard and screen reader users know that validation occurred.
Mark invalid controls programmatically. Do not rely on red text or a red border alone. Include an icon, an “Error” label, or explanatory text, and ensure the message is connected to the control.
<label for="email">Email address</label>
<p id="email-hint">We will send your receipt here.</p>
<input
id="email"
name="email"
type="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>Annotate the wireframe
For every field, record:
- The visible label and whether it is required.
- The hint, accepted format, and autocomplete purpose.
- The validation rule and exact error message.
- Where focus moves after an error.
- How the error is conveyed without color alone.
Exercise
What is wrong with a required email field that has only the placeholder “Email” and turns red after an invalid submission?
Show answer
It has no persistent label, gives no useful instruction, and uses color as the only error signal. Add a visible label, a connected hint, a specific text error, and a programmatic invalid state.