Content · Web Development · HTML

HTML Accessible Errors in Long Forms

Accessible Errors in Long Forms: The error summary has links back to the fields, reducing the amount of hunting through a long form. Includes a practical HTML example and an explanation.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Imagine asking a friend for some information on a webpage. The field should explain exactly what you need.

What You Need to Know


The error summary has links back to the fields, reducing the amount of hunting through a long form.

Try the Example


Take a look at the example. We’ll explain the important lines right below it.

<div role="alert" aria-labelledby="form-errors-title">
    <h2 id="form-errors-title">Please fix these errors</h2>
    <ul>
        <li><a href="#email-field">Enter a valid email</a></li>
        <li><a href="#age-field">Enter your age</a></li>
    </ul>
</div>
<form action="/apply" method="post">
    <label for="email-field">Email</label>
    <input id="email-field" name="email" type="email" aria-invalid="true" required>
    <label for="age-field">Age</label>
    <input id="age-field" name="age" type="number" min="1" required>
    <button type="submit">Continue</button>
</form>

Let’s Read the Code


  • for: For connects a label or output with a control by ID.
  • <h2>: A heading divides the page into understandable parts.
  • <form>: The form groups controls and identifies where submitted data goes.
  • aria-labelledby: Aria-labelledby uses the text of another element as the accessible name.

Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.

What Happens in the Browser?


The HTML controls work in the browser, but saving an answer requires the example action path to be handled by a real server.

Where does the answer go? The example uses the submitted name(s) email, age. Those names help the receiving server identify each answer. A label is for people; a name attribute is for the form data; an ID connects elements in the page.

Your Turn


Follow the error links using Tab and Enter; check that the focus target is the intended control.

Common Beginner Mistakes


  • Copying the example without giving the fields a clear label and a usable name.
  • Only add aria-invalid when the corresponding field is actually invalid, and update errors after a new validation attempt.

Key Takeaways


  • A control needs a clear label and, when submitted, a meaningful name and value.
  • for: For connects a label or output with a control by ID.
  • A meaningful HTML element is usually a stronger starting point than adding an ARIA role to a generic div. Also check what happens using only the keyboard.
Share this resourceSend this page to someone who may find it useful.