Accessibility — HTML

Accessibility means everyone can use your page. Use real tags (<button>, <a>, <nav>) before ARIA (extra attributes for screen readers). Images need alt, icon…

On a sign-up form, a wrong field only turns red. For most people that's enough. But a colour-blind user may not notice that anything is wrong, and then wonder why the form can't be sent.

Accessibility (often shortened to a11y) means everyone can use your page. That includes colour-blind users, blind users with a screen reader (a program that reads the screen aloud), and people who only use a keyboard. There are two ways to do it: use the right HTML tag, and give every image, button and input some text that can be read aloud.

Use the right tag

<button>Click Me</button>
<img src="photo.jpg" alt="User profile photo">
<nav aria-label="Main menu">
  <a href="#home">Home</a>
  <a href="#about">About</a>
</nav>

A version made only of <div> tags can look exactly the same, but the version above works with a keyboard and screen readers read it correctly.

A name for icon buttons: aria-label

<button aria-label="Close menu">×</button>

Labels, roles, and decoration

<nav role="navigation">...</nav>
<label for="name">Name:</label>
<input type="text" id="name">
<span aria-hidden="true">***</span>

Don't rely on colour alone

Colour-blind users may not notice a wrong field if the only sign is the colour red. Add a text message or an icon, such as "Email is empty". The contrast (the difference between light and dark) between text and its background should also be at least 4.5:1 (a contrast checker tool measures this number), so the text stays readable.

⚠️ What makes screen readers misread and keyboard users get lost

🔬 Try it yourself

The two tools below show what a screen reader reads from your HTML, and how a screen reader announces a message that has just appeared.

TL;DR: Accessibility means everyone can use your page. Use real tags (<button>, <a>, <nav>) before ARIA (extra attributes for screen readers). Images need alt, icon buttons need aria-label, and <label for> must match the input's id. role names an element's role, and aria-hidden="true" hides decoration from screen readers. Never mark an error with colour alone, and keep contrast at least 4.5:1.

⚡ Use the real tag

Write:

<button>Click Me</button>
<img src="photo.jpg" alt="User profile photo">

Meaning: A real <button> can be reached with Tab, works when you press Enter, and a screen reader reads it as "button". A <div> made to look like a button gets none of that. alt is read aloud in place of the image, so write what the image shows, not the word "image" or its file name.

⚡ A name for icon buttons

Write:

<button aria-label="Close menu">×</button>
Guess first: does a button that says "Save" need aria-label?

No. The word "Save" is already its name. With aria-label, a screen reader would read the aria-label and not that word.

Meaning: A button that only holds an icon has no clear name. aria-label gives it one, so a screen reader says "Close menu, button". Use the right tag first, and ARIA (attributes that start with aria-) only when plain HTML isn't enough.

⚡ Don't rely on colour alone

Meaning: Don't mark a wrong form field with red alone, because colour-blind users may not notice. Add a text message, such as "Email is empty", and keep the contrast (the difference between light and dark) between text and its background at least 4.5:1.

What you will learn