Web accessibility (often written a11y) means making sites that everyone can use, including people who are blind and use screen readers, people who cannot use a mouse, people with low vision or colour blindness, and people with temporary injuries or slow connections. Most accessibility comes from using HTML correctly, so it costs little when built in from the start. This lesson covers the habits that matter most.
In this lesson you will learn
- Why semantic HTML is the foundation
- Labels, error messages and
autocompletein forms - Keyboard access, focus styles and skip links
- Alt text, link text and colour contrast
- When to use ARIA, and how to test
This lesson builds on HTML Semantic Elements and HTML Forms.
An Accessible Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accessible form</title>
<style>
body { font-family: sans-serif; margin: 10px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 10px; top: 10px; background: #ffeb3b; padding: 6px; }
label { display: block; margin-top: 8px; font-weight: bold; }
input, button { font-size: 15px; padding: 6px; }
:focus-visible { outline: 3px solid #ff8f00; outline-offset: 2px; }
.error { color: #b71c1c; }
button { margin-top: 10px; background: #0d47a1; color: #fff; border: 0; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
</style>
</head>
<body>
<a class="skip" href="#form">Skip to form</a>
<form id="form" novalidate>
<label for="name">Full name</label>
<input id="name" name="name" autocomplete="name" required>
<label for="email">Email</label>
<input id="email" type="email" autocomplete="email" aria-describedby="email-err" aria-invalid="true">
<p id="email-err" class="error">Enter an email address like name@example.com</p>
<button type="submit">Register <span class="sr-only">for the workshop</span></button>
</form>
</body>
</html>
Result
- Every input has a
<label for="...">matching itsid. Screen readers announce the label, and clicking the label focuses the field. A placeholder is not a replacement for a label. autocomplete="name"and"email"let browsers fill in details, which helps everyone, especially people with motor or memory difficulties.aria-describedbyconnects the error text to the field, so it is read aloud with the label.aria-invalid="true"marks the field as having an error. The error is shown in text, not only by colour.- The skip link is hidden until it receives keyboard focus. Press Tab inside the result to see it appear; it lets keyboard users jump past repeated navigation.
:focus-visiblegives a clear outline to the focused element. Tab through the form to follow it.- The
sr-onlyclass hides text visually but keeps it for screen readers, giving the button a fuller name: “Register for the workshop”.
Good and Bad Patterns
<!-- BAD: looks like a button but keyboard and screen-reader users cannot use it -->
<div class="btn" onclick="save()">Save</div>
<!-- GOOD: a real button is focusable and works with Enter and Space -->
<button type="button" onclick="save()">Save</button>
<!-- Icon-only button needs an accessible name -->
<button type="button" aria-label="Close dialog">×</button>
<!-- Images: describe meaning, or use empty alt for decoration -->
<img src="graph.png" alt="Sales rose from 20 to 45 orders between January and March">
<img src="divider.png" alt="">
<!-- Links should make sense out of context -->
<a href="/fees.pdf">Download the 2026 fee schedule (PDF, 200 KB)</a> <!-- not "click here" -->
<!-- Landmarks help screen-reader users jump around the page -->
<header>...</header>
<nav aria-label="Main">...</nav>
<main id="main">...</main>
<footer>...</footer>
<!-- A status message that screen readers announce when it changes -->
<p role="status" aria-live="polite" id="save-status"></p>
- A
<div>with a click handler cannot be reached with Tab or activated with Enter. A real<button>works with the keyboard and announces itself as a button, for free. - Icon-only buttons need an accessible name, here from
aria-label. alttext describes what an image means in context. Decorative images get an emptyalt=""so screen readers skip them; leaving outaltentirely makes some readers announce the file name.- Link text should make sense on its own, because screen-reader users often list all links on a page. “Click here” repeated ten times is useless.
- Landmark elements (
header,nav,main,footer) let users jump between page regions. aria-live="polite"makes screen readers announce a status message when JavaScript changes it, such as “Saved”.
Quick Accessibility Checklist
| Check | How |
|---|---|
| Page language set | <html lang="en"> (or bn for Bangla) |
One h1 and headings in order | Do not skip from h2 to h4 |
| Text contrast at least 4.5:1 | Use a contrast checker or browser DevTools |
| Everything works with the keyboard | Unplug the mouse and use Tab, Shift+Tab, Enter, Space |
| Visible focus indicator | Never use outline: none without a replacement |
| Images have suitable alt text | Meaningful text, or alt="" for decoration |
| Forms have labels and text errors | label for, aria-describedby |
| Video has captions | <track kind="captions"> |
The first rule of ARIA: if a native HTML element does the job, use it instead of adding ARIA. Automated tools such as Lighthouse (in Chrome DevTools) and axe catch many problems, but always finish with a keyboard test and, if you can, a screen reader such as NVDA (Windows) or VoiceOver (Mac and iPhone).
Common Mistakes
- Clickable divs and spans instead of buttons and links.
- Removing focus outlines for looks.
- Using colour alone to show errors or required fields.
- Light grey text on white that fails contrast.
Practice Exercises
Exercise 1. Fix this search box: <input placeholder="Search"><div onclick="go()">🔍</div>
Show answer
<label for="q" class="sr-only">Search tutorials</label>
<input id="q" type="search" placeholder="Search">
<button type="submit" aria-label="Search">🔍</button>
Exercise 2. Write suitable alt text for a photo of the 2026 graduation ceremony used on a news page, and for a decorative wave graphic.
Show answer
<img src="grad.jpg" alt="Graduates throwing their caps at the 2026 convocation">
<img src="wave.svg" alt="">
Frequently Asked Questions
What is WCAG?
The Web Content Accessibility Guidelines, published by the W3C, are the international standard for accessibility. Most laws and organisations aim for WCAG 2.2 level AA.
Does accessibility help SEO?
Often, yes. Search engines read headings, link text, alt text and page structure much as screen readers do, so the same good practices help both. See Meta Tags and SEO.
Summary
- Semantic HTML gives most accessibility for free.
- Label every input, show errors in text, and support autocomplete.
- Make everything keyboard-usable with visible focus.
- Write meaningful alt and link text, keep contrast high, and use ARIA only when HTML cannot do the job.
