Chapter 23 of 26

Accessibility Basics

Imagine visiting your college's exam registration page and being unable to complete it: the form fields have no names you can hear, the "Submit" button can't be reached with the keyboard, and the important notice is an image with no description. For millions of people, that is an everyday experience on the web.

The World Health Organization estimates that about 1.3 billion people, roughly 1 in 6 of the world's population, live with a significant disability. Many of them use the web with tools like screen readers, keyboards only, voice control or screen magnifiers. Whether they can use your page depends mostly on the HTML you write. The good news: if you've followed this tutorial's advice on semantic HTML, you've already done half the work.


What is Web Accessibility?

Web accessibility (often shortened to a11y: "a", 11 letters, "y") means designing and building websites so that people with disabilities can perceive, understand, navigate and interact with them.

Accessibility helps people with many kinds of needs:

Need

Examples

What helps

Visual

Blindness, low vision, colour blindness

Screen readers, alt text, good contrast, zoom that doesn't break the layout

Motor

Can't use a mouse, tremors, a broken arm

Full keyboard support, large click targets, voice control

Hearing

Deaf or hard of hearing

Captions and transcripts for audio and video

Cognitive

Dyslexia, ADHD, memory difficulties

Clear language, consistent layout, helpful error messages

It also helps everyone else: a student watching a lecture video with captions in a noisy hostel, a user on a cheap phone in bright sunlight (contrast!), or a power user who prefers the keyboard. Disabilities can be permanent, temporary (a fractured wrist) or situational (holding a baby in one arm).


How a Screen Reader Sees Your Page

A screen reader is software that reads the page aloud (or sends it to a braille display) and lets the user navigate by headings, links, landmarks and form fields. Popular ones are NVDA (free, Windows), JAWS (Windows), VoiceOver (built into macOS and iOS), TalkBack (Android) and Narrator (Windows).

Screen readers don't look at your pixels. The browser builds an accessibility tree from your HTML: a simplified version of the DOM in which every important element has a role (what it is), a name (what it's called) and a state (checked, expanded, disabled, ...).

HTML                                        Accessibility tree
<button type="submit">Register</button>  →  role: button,   name: "Register"
<div onclick="go()">Register</div>       →  role: generic,  name: (none) … just text
<input type="checkbox" id="t" checked>
<label for="t">I agree</label>            →  role: checkbox, name: "I agree", state: checked

This is the whole idea in one diagram: the correct HTML element gives assistive technology the correct role, name and state for free. A <div> styled to look like a button is, to a screen reader, just a piece of text.


The Standard: WCAG and POUR

The international standard is the Web Content Accessibility Guidelines (WCAG), published by the W3C. The current version is WCAG 2.2 (a W3C Recommendation since October 2023). WCAG 3 is being drafted but is not a finished standard, so laws and companies around the world, including Indian government website guidelines, still point to WCAG 2.x.

WCAG is organised around four principles, remembered as POUR:

Principle

Meaning

Example

Perceivable

Users must be able to sense the content

Alt text for images, captions for videos, enough contrast

Operable

Users must be able to use every control

Everything works with a keyboard; no time limits that are too short

Understandable

Content and behaviour must make sense

Page language set, clear labels and error messages

Robust

Works with current and future assistive technology

Valid, semantic HTML with correct roles, names and states

Each guideline has success criteria at three levels: A (minimum), AA (the usual legal and industry target) and AAA (highest). When a job description says "WCAG 2.2 AA compliance", it means meeting all A and AA criteria.


Rule 1: Use the Right Element

Most accessibility comes from choosing semantic elements, which we studied in the Semantic HTML chapter. Compare a typical inaccessible form with a fixed version.

Before: Looks Fine, Works Badly

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Register</title>
</head>
<body>
  <div class="title">Register for the Coding Contest</div>
  <img src="contest-banner.png">
  Name <input type="text" id="name">
  Email <input type="email" id="email">
  <div class="btn" onclick="register()">Submit</div>
  <p>For rules, <a href="rules.html">click here</a>.</p>
</body>
</html>

To a sighted mouse user this page looks OK. But:

  • No lang: a screen reader may read the English text with the wrong voice and pronunciation.

  • The "title" is a <div>, so screen reader users jumping by headings find no headings at all.

  • The image has no alt, so the screen reader may read out the file name, "contest-banner.png", and the date and time it shows are lost.

  • The inputs have no labels. The screen reader announces "edit text, blank" twice; the user doesn't know which is which.

  • The "button" is a <div>: it can't be reached with Tab, can't be activated with Enter or Space, and isn't announced as a button.

  • "click here" means nothing when a screen reader lists all the links on the page.

After: Same Content, Accessible

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Register | Coding Contest 2026</title>
</head>
<body>
  <a href="#main">Skip to main content</a>

  <header>
    <nav aria-label="Main">
      <a href="/">Home</a>
      <a href="/contests">Contests</a>
    </nav>
  </header>

  <main id="main">
    <h1>Register for the Coding Contest</h1>
    <img src="contest-banner.png" width="600" height="200"
         alt="Coding Contest 2026: Saturday 14 November, 10 AM to 1 PM, online">

    <form action="/register" method="post">
      <p>
        <label for="name">Full name</label>
        <input type="text" id="name" name="name" autocomplete="name" required>
      </p>
      <p>
        <label for="email">Email</label>
        <input type="email" id="email" name="email" autocomplete="email"
               required aria-describedby="email-hint">
        <small id="email-hint">We'll send your contest link here.</small>
      </p>
      <button type="submit">Register</button>
    </form>

    <p>Read the <a href="rules.html">contest rules</a> before you start.</p>
  </main>

  <footer>
    <p>© 2026 CS Club</p>
  </footer>
</body>
</html>

Output (in the browser):

Skip to main content
Home Contests

Register for the Coding Contest            (large heading)
[image]                                     (if the image fails to load, the
                                             browser shows its alt text instead)
Full name [__________]
Email [__________] We'll send your contest link here.
[Register]
Read the contest rules before you start.
© 2026 CS Club

Each change and the problem it solves:

Fix

Why it helps

lang="en"

Correct pronunciation by screen readers; correct translation and hyphenation

<header>, <nav>, <main>, <footer>

Become landmarks: users can jump straight to "main" or "navigation"

<h1>

Screen reader users often navigate by headings first

Descriptive alt

The image's information (date and time) is available as text

<label for="...">

Each field is announced with its name; clicking the label also focuses the field, a bigger target for everyone

aria-describedby

The hint is read after the field's name: "Email, edit text, required, We'll send your contest link here"

autocomplete

Browsers can fill in name and email, which helps people with motor or memory difficulties

A real <button>

Focusable, works with Enter and Space, announced as "button"

Skip link

Keyboard users can jump past the navigation on every page

Meaningful link text

"contest rules" makes sense out of context


Writing Good Alt Text

We introduced alt in the Images chapter. The question to ask is: "If I replaced this image with text, what would I write?"

Image type

What to write

Example

Informative (carries information)

The information, briefly

alt="Bar chart: pass rate rose from 62% in 2024 to 81% in 2026"

Decorative (just looks nice)

An empty alt, so screen readers skip it

alt=""

Functional (inside a link or button)

What the link or button does

A search icon button: alt="Search", not alt="magnifying glass"

Image of text

The same text

A banner reading "Admissions Open": alt="Admissions Open"

Note the difference between alt="" (deliberately empty: "ignore me") and no alt at all (a mistake: the screen reader may read out the file name). Don't start with "Image of..." either; the screen reader already announces it as an image.


Keyboard Accessibility

Many users never touch a mouse. Test every page by putting the mouse aside and using only these keys:

Key

Action

Tab / Shift + Tab

Move to the next / previous focusable element

Enter

Follow a link, press a button

Space

Press a button, toggle a checkbox

Arrow keys

Move between radio buttons, options in a select, scroll

Esc

Close a dialog or popover

Things to check: can you reach every control? Can you see where focus is (never remove the focus outline with CSS without providing a replacement)? Does the order make sense?

The tabindex Attribute

Links, buttons and form fields are focusable automatically. tabindex changes that:

Value

Effect

Use it?

tabindex="0"

Element joins the Tab order, in its normal document position

Only for custom widgets; prefer a native element

tabindex="-1"

Not in the Tab order, but focusable from JavaScript with .focus()

Yes, e.g. to move focus to an error summary

tabindex="1" or higher

Jumps ahead of everything else in the Tab order

Avoid: it creates a confusing order that's hard to maintain


ARIA: Use It Carefully

WAI-ARIA (Accessible Rich Internet Applications) is a set of attributes (role and aria-*) that add or change the role, name and state information in the accessibility tree.

ARIA changes only what assistive technology is told. It doesn't add any behaviour. <div role="button"> is announced as a button, but it still isn't focusable and still ignores Enter and Space unless you add tabindex and JavaScript yourself. That leads to the famous first rule of ARIA:

If a native HTML element or attribute already has the meaning and behaviour you need, use it instead of adding ARIA.

Even so, a few ARIA attributes are useful every day:

Attribute

Purpose

Example

aria-label

Gives a name when there is no visible text

<button aria-label="Close">✕</button>

aria-labelledby

Uses another element's text as the name

<dialog aria-labelledby="dialog-title">

aria-describedby

Adds extra description (hints, error messages)

The email hint in our form

aria-expanded

Says whether a controlled section is open

A custom menu button: aria-expanded="false"

aria-live="polite"

Announces content that changes without a page reload

"3 results found", "Saved"

aria-hidden="true"

Hides decorative content from assistive technology

A decorative icon next to text

Never put aria-hidden="true" on something focusable: keyboard users would land on an element that the screen reader says doesn't exist.


Colour and Contrast

Light grey text on white may look elegant, but many people can't read it. WCAG level AA asks for a contrast ratio of at least:

  • 4.5 : 1 for normal text

  • 3 : 1 for large text (about 24px, or about 18.7px bold) and for important parts of controls and icons

The ratio goes from 1 : 1 (same colour) to 21 : 1 (black on white). Some real values on a white background:

Text colour

Ratio on white

Normal text AA?

#000000 (black)

21 : 1

Pass

#595959 (dark grey)

7 : 1

Pass

#767676 (grey)

4.54 : 1

Pass (just)

#777777 (grey)

4.48 : 1

Fail (just)

#aaaaaa (light grey)

2.32 : 1

Fail

Also, never use colour as the only signal. "Fields in red are required" fails for colour-blind users; add text such as "(required)" or an icon with a text alternative.


Other Quick Wins

  • Tables: use <th> for headers (with scope="col" or scope="row") and a <caption>, as in the Tables chapter, so each cell can be announced with its header.

  • Media: add captions to videos with <track kind="captions"> (see the Audio & Video chapter) and never autoplay sound.

  • Iframes: give each one a title describing its content.

  • Zoom: don't block zooming in the viewport meta tag (avoid user-scalable=no and maximum-scale=1).

  • Target size: WCAG 2.2 asks for click/tap targets of at least 24 × 24 CSS pixels (or enough space around smaller ones).

  • Error messages: say what went wrong and how to fix it, in text, next to the field.


Testing Accessibility

Use a mix of automated and manual checks:

  1. Automated tools: Lighthouse (built into Chrome DevTools), axe DevTools and WAVE browser extensions, or an HTML checker like html-validate.

  2. Keyboard test: complete the main task using only Tab, Enter, Space, arrows and Esc.

  3. Screen reader test: try NVDA on Windows or VoiceOver on a Mac or iPhone for a few minutes. Listen to your headings, links and form labels.

  4. Zoom test: zoom to 200% and check nothing is cut off or overlapping.

Automated tools find only part of the problems. When we ran npx html-validate on the "before" page above, this was the complete report:

  2:2  error  <html> is missing required "lang" attribute  element-required-attributes
  9:4  error  <img> is missing required "alt" attribute    wcag/h37

✖ 2 problems (2 errors, 0 warnings)

Only 2 of the 6 problems we listed were caught. Nothing flagged the <div> heading, the <div> button, the unlabelled inputs or "click here". Software can check whether an attribute exists; only a human can judge whether the page actually makes sense.


Common Mistakes

  • Clickable <div>s and <span>s instead of <button> and <a>.

  • Placeholder instead of a label. The placeholder disappears when you type, is often low-contrast, and isn't a reliable name.

  • Skipping heading levels or choosing headings for their size. Use levels for structure, CSS for size.

  • Removing focus outlines with outline: none and no replacement.

  • Adding ARIA everywhere. Wrong ARIA is worse than none; it gives screen readers false information.

  • Alt text that repeats nearby text or says "image of image".


Interview Questions

What is the first rule of ARIA?

Don't use ARIA if a native HTML element or attribute already gives the semantics and behaviour you need. For example, use <button> rather than <div role="button">, because the native button is focusable and keyboard-operable automatically, while ARIA only changes how the element is announced.

What does POUR stand for?

Perceivable, Operable, Understandable and Robust: the four principles of WCAG.

When should an image have alt=""?

When it is purely decorative or its information is already given in nearby text. Empty alt tells screen readers to skip the image. Missing alt is different and is an error.

What is the minimum contrast ratio for normal text at WCAG AA?

4.5 : 1. For large text (about 24px regular or 18.7px bold) it is 3 : 1.

Why should you avoid positive tabindex values?

They pull elements to the front of the Tab order, ahead of the natural document order, which confuses keyboard users and becomes hard to maintain. Use the natural order (no tabindex), 0 to add a custom element to the order, or -1 for elements you only focus from script.

What is the accessibility tree?

A structure the browser builds from the DOM for assistive technology. Each node has a role, an accessible name, states and properties. Screen readers read this tree, not the visual rendering.

Conclusion

  • Accessibility means everyone, including people with visual, motor, hearing and cognitive disabilities, can use your page. It benefits all users.

  • The browser turns your HTML into an accessibility tree of roles, names and states, so semantic HTML is the foundation.

  • Follow WCAG 2.2 (target level AA) and its POUR principles.

  • Must-dos: lang, headings, landmarks, alt text, labels, real buttons and links, visible focus, enough contrast, captions.

  • Use ARIA only to fill gaps that HTML can't, and test with a keyboard and a screen reader, not just automated tools.

Much of what makes a page accessible also makes it easy for search engines to understand. That's the subject of the next chapter, HTML for SEO.