Course contentsShow
← Web Development
Lesson 928 of 2,98216. Forms and ValidationFree lesson

Input Descriptions and Help Text

Providing helpful instructions with aria-describedby, distinguishing between errors and help text.

Input Descriptions and Help Text

What you'll learn: How to provide helpful instructions alongside form fields using aria-describedby and distinguish them from error messages.

The Difference Between Help Text and Error Messages

Help text explains what to enter before the user makes a mistake, while error messages explain what went wrong after validation fails. Think of help text as friendly instructions you'd give someone before they start a task, and errors as corrections you offer when something needs fixing.

These serve different purposes and should be communicated differently to all users, including those using assistive technologies.

Using aria-describedby for Help Text

The aria-describedby attribute links an input to descriptive text by referencing the ID of the element containing the help text:

<label for="username">Username</label>
<input 
  type="text" 
  id="username" 
  aria-describedby="username-help"
>
<div id="username-help">
  Must be 3-20 characters, letters and numbers only
</div>

When a screen reader focuses this input, it announces: "Username, edit text, Must be 3-20 characters, letters and numbers only."

Combining Help Text with Error Messages

You can reference multiple IDs in aria-describedby, separating them with spaces:

<input 
  type="email" 
  id="email"
  aria-describedby="email-help email-error"
  aria-invalid="true"
>
<div id="email-help">We'll never share your email</div>
<div id="email-error">Please enter a valid email address</div>

Help text persists throughout the user's interaction, while error messages appear only when validation fails. The aria-invalid attribute signals the error state.

Key Takeaway: Use aria-describedby to connect inputs with persistent help text, and combine it with error message IDs when validation fails—this ensures all users receive both guidance and feedback in context.