Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How do I connect form instructions and error explanations to a field?

Quick answer

Give the input a clear visible label. Put its instruction and any error explanation in elements with IDs, then reference the relevant IDs in the input’s aria-describedby attribute. When the value is invalid, aria-invalid="true" can indicate that state. Keep the messages specific: say what information is expected, and, for an error, what went wrong and how to fix it. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

What’s the basic pattern for connecting instructions and errors to a form field? I want people to understand what to enter and how to fix a problem.

Geez

Give the input a visible label, then put its instruction and error explanation in separate elements with their own IDs. Reference the relevant IDs from the input using aria-describedby. The attribute identifies elements that describe an object; the cited guidance illustrates connecting explanatory text by ID. [S1] Guidance also recommends labeling every input and writing errors that explain what went wrong and how to fix it. [S2]

For example, if the form requires a date in a particular format, the instruction could say “Enter the date as MM/DD/YYYY.” If the entry fails that rule, an error could say “Enter the date as MM/DD/YYYY.” Use the form’s actual requirements; these example words don’t establish rules for a real form.

<label for="appointment-date">Appointment date</label>
<p id="date-help">Enter the date as MM/DD/YYYY.</p>
<input id="appointment-date"
       name="appointment-date"
       aria-describedby="date-help date-error"
       aria-invalid="true">
<p id="date-error">Enter the date as MM/DD/YYYY.</p>

This shows an invalid state. The error text and aria-invalid="true" should reflect the field’s actual state, not appear as a permanent warning.

Follow-up question

Should the instruction and error share one ID, or should I give them separate IDs?

Geez

Give each text element its own ID so the field can reference the descriptions that apply. In the example, date-help identifies the instruction and date-error identifies the error; both are listed in aria-describedby. The attribute can identify one or more descriptive elements by ID. [S1]

Keep the messages useful as well as connected. An instruction should say what to enter, and an error should state what went wrong and how to fix it. [S2] For example, “Invalid date” names a problem but gives no correction; a format-specific message gives a next step when that format is the actual requirement.

Check that each referenced ID exists and belongs to the intended field. Include an error ID only when that error text is present and relevant.

Follow-up question

What should change when validation finds an error? Can you show the field before and after?

Geez

Before a problem is found, show the label and instruction without marking the field invalid. When the value fails the form’s rule, show a specific error, include its ID in aria-describedby, and set aria-invalid="true". The cited guidance describes aria-invalid as indicating that a value does not conform to an expected format. [S1]

For a valid state, remove the error text and its ID from aria-describedby, and don’t mark the field invalid. Keep the label and any relevant instruction. These snippets illustrate associations; they do not specify how a particular application validates or clears errors. Use the field’s real rules.

Follow-up question

How can I review several fields for mismatched descriptions or unhelpful errors?

Geez

Review each field’s label, instruction, and any current error together. Check that the IDs referenced by the input point to text for that same field. Then ask: does the label make the field’s purpose clear, does the instruction state what is expected, and does the error explain what went wrong and how to fix it? [S2]

Use examples that should pass and fail under the form’s stated rules to review the content and state changes. Confirm the error and invalid state correspond to an actual problem and are no longer present once the value is corrected. This review does not establish complete accessibility or behavior in every environment; the cited guidance supports the described associations and writing advice, not a full validation implementation. [S1] [S2]

A practical checklist

  • Give the input a clear visible label.

  • State the actual expected format or constraint in the instruction.

  • Use IDs for descriptive text and reference the relevant IDs in aria-describedby.

  • Make each error explain what went wrong and how to fix it.

  • Check that referenced IDs exist and describe the intended field; reflect the field’s actual state.

A few more useful answers

Can `aria-describedby` reference both instructions and an error?

It can identify one or more descriptive elements by ID. Reference the descriptions that apply to the field’s current state. [S1]

Does `aria-describedby` replace a visible field label?

No. Keep a clear label; the guidance recommends labeling every input field. [S2]

Does this example specify a complete validation implementation?

No. It illustrates associating descriptive text and indicating an invalid value. It does not specify every validation behavior. [S1]

Sources

References used for this guide.

  1. [S1] Accessibility in forms, products, and controls
    learn.microsoft.com · Checked
  2. [S2] Write accessible documentation
    developers.google.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work