How do you make forms accessible?

IntermediateHTML and accessibility interview questionBy , updated 17 November 2026

Short answer

To make a form accessible, give every control a visible <label> tied to it, group related controls in a <fieldset> with a <legend>, mark required fields with required and words, add autocomplete tokens, and write errors as text linked to the field with aria-describedby and aria-invalid="true". On a failed submit, move focus to an error summary or the first invalid field. Never use a placeholder as the label.

Start with native controls and labels

A native <input>, <select> or <textarea> already has a role, a value, keyboard support and states that assistive technology understands. What it lacks is a name, and the label provides it:

<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required />

for must match the input's id. Wrapping the input inside the <label> also works. Either way, the screen reader announces "Email address, edit text, required", and clicking the label focuses the input, which gives mouse and touch users a bigger target. That matters most for checkboxes and radio buttons.

If a design has no visible label, such as a search box with an icon, give it an accessible name with aria-label or a visually hidden label (see How do you hide content visually but keep it for screen readers?). A visible label is still better for everyone.

Do not use a placeholder as the label

A placeholder disappears as soon as the user types, so they cannot check what the field was for. Its default colour is usually too pale for good contrast, and assistive technologies do not treat it consistently as a name. Use it, if at all, for a short example format, and keep the real label and hint as text outside the field.

A radio group needs a question as well as options. The <legend> is that question, and screen readers announce it when focus enters the group:

<fieldset>
  <legend>Delivery speed</legend>
  <label><input type="radio" name="speed" value="standard" checked /> Standard (3 to 5 days)</label>
  <label><input type="radio" name="speed" value="express" /> Express (next day)</label>
</fieldset>

Use the same pattern for checkbox groups and for related text fields, such as the parts of an address or a date of birth split into day, month and year.

Required fields, types and autocomplete

  • required is exposed to assistive technology and blocks native submission. Also say it visibly: "(required)" in the label, or a note explaining what the asterisk means. Use aria-required="true" only on custom controls that cannot take required.
  • Input types such as email, tel and url bring the right mobile keyboard. For numbers that are not quantities (PIN codes, card numbers, OTPs), use type="text" with inputmode="numeric", because type="number" adds spinners and drops leading zeros.
  • autocomplete tokens (name, email, tel, street-address, postal-code, current-password, new-password, one-time-code) let browsers and password managers fill fields. That helps people with motor or memory difficulties a great deal, and it is how you meet WCAG success criterion 1.3.5 (Identify Input Purpose, level AA) for fields that collect the user's own details.

Error messages that everyone gets

An error has to be perceivable without colour, tied to its field, and specific enough to fix:

<div class="field">
  <label for="phone">Mobile number</label>
  <p id="phone-hint" class="hint">10 digits, without +91</p>
  <input id="phone" name="phone" type="tel" inputmode="numeric" autocomplete="tel-national"
         aria-describedby="phone-hint phone-error" aria-invalid="true" />
  <p id="phone-error" class="error">Enter a 10-digit mobile number, for example 9876543210.</p>
</div>
  • aria-describedby takes a space-separated list of ids, so the hint and the error are both read after the label when the field is focused.
  • aria-invalid="true" makes the screen reader say "invalid entry". Set it only after validation has run, not on page load, and remove it when the value is fixed.
  • The message says what to do, not just "Invalid". Pair the red colour with an icon or the word "Error" so it does not depend on colour alone.
  • aria-errormessage exists for this purpose too, but support has been uneven, so aria-describedby is the safer choice.

On submit: focus and announcements

When a submitted form fails, a sighted user sees red text; a screen reader user hears nothing unless you tell them. Two patterns work:

  1. Move focus to an error summary at the top that lists each problem as a link to its field. Good for long forms.
  2. Move focus to the first invalid field. Its label, hint and error are read straight away. Good for short forms.
// <form id="signup" novalidate>: native bubbles off, constraint checks still on
const form = document.querySelector("#signup");

form.addEventListener("submit", (event) => {
  const fields = [...form.querySelectorAll("input, select, textarea")].filter((el) => el.willValidate);
  const invalid = fields.filter((el) => !el.checkValidity());
  for (const el of fields) {
    el.setAttribute("aria-invalid", String(invalid.includes(el)));
  }
  if (invalid.length > 0) {
    event.preventDefault();
    invalid[0].focus(); // label, hint and error are announced
  }
});

The form uses novalidate so you show your own messages, while the Constraint Validation API (checkValidity(), validity, setCustomValidity()) still does the checking. Write the matching error text into each field's error element in the same step.

For changes that happen without moving focus, such as "Saved" after an autosave or "Message sent" when the form stays on screen, use a live region: role="status" for polite messages and role="alert" for urgent ones. The region must already be in the DOM before you put text in it, or some screen readers will miss the update. Do not combine a focus move and an alert for the same error; users hear it twice.

Other details that matter

  • Do not disable the submit button until the form is valid. Users cannot tell why it does nothing, and disabled buttons are skipped by the Tab key. Let them submit and explain the errors.
  • Keep what they typed after an error. Clearing fields fails users who type slowly or use dictation.
  • Visible focus on every control, with :focus-visible styles that meet contrast.
  • Validate on blur or submit, not on every keystroke, so a half-typed email is not announced as an error.
  • Do not ask for the same information twice in one process (WCAG 2.2, 3.3.7 Redundant Entry), and allow paste in password and OTP fields.
  • Custom controls (comboboxes, date pickers, toggles) need full ARIA and keyboard support. Prefer a native control when one fits.

The page-wide checklist is in How do you make a website accessible?, and the attributes used here are explained in What is ARIA, and when should you use it?.

Practise it

Common follow-up questions

Is HTML5 validation accessible enough on its own?

It is a reasonable baseline: required fields and types are announced, and invalid fields get focus. But the browser's error bubbles disappear quickly, cannot be styled, and are worded generically. Most teams use novalidate, keep the Constraint Validation API for the logic, and render their own text errors.

Should errors appear while the user types?

Usually not. Validate when the user leaves the field or submits. Live validation is fine for positive feedback such as a password strength meter, if it is polite and does not interrupt.

How do I label a field when the design has no room for a label?

Ask for the label anyway; it is the single biggest win. If the design truly cannot show one, use a visually hidden <label>, which keeps the click target and the accessible name, rather than only a placeholder.

How do I make IDs unique in a React form that repeats?

Use useId() to generate a base id per field group and build for, aria-describedby and error ids from it. It also stays the same between server rendering and hydration.

Mistakes to avoid

  • A placeholder instead of a label, or a label not connected to its input

  • Radio buttons with no <fieldset> and <legend>, so the question is never read

  • Errors shown only in red, or not linked to the field

  • Setting aria-invalid="true" before the user has done anything

  • Disabling the submit button instead of explaining what is wrong

  • Adding a live region at the moment of the error, so it is not announced

  • Wiping the form after a failed submit

Practise it in code

Interviewers rarely stop at the definition. These questions open in an editor with tests.

  1. Mark up an accessible signup form with labels, a fieldset, hints and error messagesEasy20 min
  2. Fix a div-soup form so it works with a keyboard and screen readersEasy25 min
  3. Validate a form with the Constraint Validation API: setCustomValidity, custom messages and aria-invalidEasy25 min
  4. Wire repeated address fields with useId: labels, hints, errors and aria-describedbyMedium30 min
  5. Style form validation states with :user-invalid, :placeholder-shown and :focus-visibleEasy20 min
  6. Build a useAnnouncer() hook for screen-reader live announcementsMedium30 min