appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Accessible forms and ARIA basics

Lesson 4 of 411 minIntermediate

Labels, validation messages and when (not) to use ARIA.

Forms are where accessibility problems hurt most. Native HTML does most of the work if you use it properly.

<form novalidate>
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required
         autocomplete="email" aria-describedby="email-hint email-error">
  <p id="email-hint">We only use it to send your receipt.</p>
  <p id="email-error" role="alert" hidden>Enter a valid email address.</p>
  <button type="submit">Send</button>
</form>
  • A visible <label> for every control. A placeholder is not a label.
  • autocomplete helps people (and password managers) fill the form.
  • aria-describedby connects hints and error messages to the field, so screen readers read them with it.
  • role="alert" makes an error message be announced when it appears.
  • Group related controls (radio buttons) with <fieldset> and <legend>.

The first rule of ARIA

ARIA attributes add meaning that HTML cannot express. The first rule: do not use ARIA if a native element does the job. <button> already has the role, keyboard support and focus. A <div role="button"> needs you to build all of it.

  • Use ARIA for custom widgets (tabs, menus, dialogs) and for dynamic state: aria-expanded, aria-current, aria-live.
  • Wrong ARIA is worse than none. It can hide or mislabel content from assistive technology.
  • Use aria-label only when there is no visible text, for example an icon button.

CarefulValidate on the server too. HTML validation attributes improve the experience but can be bypassed.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. Is a placeholder a replacement for a label?
2. What is the first rule of ARIA?
3. What does aria-describedby do on an input?