Content · Web Development · HTML

HTML Accessible Forms: Labels, Legends, and Error Messages

Accessible Forms: Labels, Legends, and Error Messages: Try moving through the elements with a keyboard. The labels and relationships matter even when no extra styling has been added. Includes a practical HTML example and an explanation.

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

Good accessibility usually starts with clear words and the right HTML elements, not a large amount of extra code.

What You Need to Know


Form labels tell people which answer belongs in each field. Fieldset and legend identify a group, while linked help text and error messages explain how to correct a problem. Placeholder text is not a dependable label.

In this example: improve an accessible signup form.

Try the Example


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

<form action="/join" method="post">
    <label for="email">Email address</label>
    <input id="email" name="email" type="email" aria-invalid="true" aria-describedby="email-error">
    <p id="email-error">Enter an email address such as [email protected].</p>
    <button type="submit">Join</button>
</form>

Let’s Read the Code


  • <form>: The form groups controls and identifies where submitted data goes.
  • <label>: The label tells people what the input is for. A matching for/id pair makes the label clickable.
  • for: For connects a label or output with a control by ID.
  • id: An id uniquely identifies an element on this page.

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?


Try this with Tab and Shift+Tab. If you can, inspect the accessibility tree too; appearance alone does not tell the whole story.

What does assistive technology receive? The example includes aria-invalid, aria-describedby. These relationships can explain names, states, or descriptions when used correctly. They do not automatically move focus, listen for clicks, or create keyboard handling.

Your Turn


Use Tab and Shift+Tab to visit the controls, then read their labels aloud. Is the purpose of each one clear?

Common Beginner Mistakes


  • Judging the page only by how it looks, without checking its meaning and keyboard behavior.
  • ARIA changes what assistive technology is told; it does not automatically add keyboard controls, visual styling, or JavaScript behavior.

Key Takeaways


  • Form labels tell people which answer belongs in each field.
  • <form>: The form groups controls and identifies where submitted data goes.
  • 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.