Course topics

By WebNest Studio Engineering Team

HTML Tutorial

HTML Accessibility Fundamentals

Accessibility means building pages that people using screen readers, keyboard-only navigation, voice control, or other assistive technology can use just as effectively as anyone else. Much of accessibility isn't a separate skill layered on top of HTML — it's simply the result of writing correct, semantic HTML in the first place.

Why it matters

Around one person in six lives with a disability, and many more use a keyboard, a small screen or a slow connection. An inaccessible site shuts them out and, in many countries, breaks the law. Most accessibility comes free from using the right HTML elements, which is why it is treated as a core skill and not as an extra.

Semantic Structure as the Accessibility Foundation

Screen readers build a navigable model of a page from its underlying structure: heading levels, landmark elements (<nav>, <main>, <header>), lists, and form labels. A page built from correctly chosen semantic elements is, by default, far more accessible than one built entirely from generic <div> and <span> elements with visual styling standing in for structure.

Text Alternatives and ARIA Basics

Every meaningful image needs descriptive alt text, as covered in HTML images. When native HTML elements and attributes can't fully express a UI pattern's role or state — a custom tab widget or an expandable accordion, for example — ARIA (Accessible Rich Internet Applications) attributes like role, aria-label, and aria-expanded can fill the gap. The first rule of ARIA, though, is to prefer a native HTML element over an ARIA-patched generic one whenever possible — a real <button> is more robust than a <div role="button"> that must have keyboard handling added manually.

  • alt — required text alternative for meaningful images.
  • aria-label — provides an accessible name when visible text isn't sufficient or present.
  • aria-expanded — communicates whether a collapsible element is currently open or closed.
  • role — declares an element's purpose when no native element expresses it, used sparingly.

Keyboard Navigation

Every interactive element — links, buttons, form controls — must be reachable and operable using only a keyboard, without requiring a mouse. Native elements like <a>, <button>, and <input> handle this automatically (they're focusable via Tab and activatable via Enter or Space by default). Custom interactive widgets built from non-interactive elements lose this behavior entirely unless it's added back manually, which is another strong reason to prefer native elements.

Example

An accessible expandable section using native elements and minimal ARIA

HTML
<button aria-expanded="false" aria-controls="details-panel" id="toggle-btn">
  Show Details
</button>
<div id="details-panel" hidden>
  <p>Additional details appear here once expanded.</p>
</div>
Output
Displays a "Show Details" button; when JavaScript toggles aria-expanded to "true" and removes the hidden attribute, screen readers announce the button as expanded and the panel content becomes available to all users, including keyboard users tabbing to the button.

Common Mistakes

  • Using a <div> or <span> with a click handler as a button instead of a real <button>, breaking keyboard access.
  • Adding ARIA roles to elements that already have the correct native semantics, which is redundant and sometimes conflicting.
  • Leaving alt attributes empty or missing on meaningful images.
  • Building custom widgets (dropdowns, modals, tabs) without any keyboard handling, trapping keyboard-only users.

Exercise

The page below has three accessibility faults: a clickable div that cannot be reached or activated with the keyboard, an image with no text alternative, and an input with no label. Fix all three using native HTML.

Expected result: the Save control is a real button that logs Saved to the console when activated with the mouse or the keyboard, the logo has the alternative text WebNest Studio, and the field has the visible label Search.

HTML · starter code
<img src="logo.png">

<div onclick="console.log('Saved')">Save</div>

<input type="text" name="q">
Show hints
  • A button element is focusable and responds to Enter and Space without any extra code.
  • Connect a label to the input with matching for and id attributes.
Show solution
HTML · solution
<img src="logo.png" alt="WebNest Studio">

<button type="button" onclick="console.log('Saved')">Save</button>

<label for="q">Search</label>
<input type="text" id="q" name="q">

Quick quiz

1. Why is <div onclick="..."> a poor substitute for a button?

  • A. It cannot be focused with the Tab key, does not respond to Enter or Space, and is not announced as a button
  • B. It is slower
  • C. Divs cannot have click handlers
  • D. It cannot be styled
Show answer

A. A real button provides all three behaviours with no extra work.

2. What is the first rule of ARIA?

  • A. Add ARIA to every element
  • B. If a native HTML element provides the behaviour you need, use it instead of ARIA
  • C. ARIA replaces semantic HTML
  • D. ARIA is only for images
Show answer

B. ARIA changes what is announced but adds no behaviour, so native elements are more reliable.

3. What does tabindex="0" do?

  • A. Makes the element first in the tab order
  • B. Removes the element from the tab order
  • C. Places the element in the keyboard tab order at its natural position
  • D. Hides the element
Show answer

C. tabindex="-1" makes an element focusable by script only. Positive values should be avoided.

Interview questions

How do you make a website accessible?

Show answer

Start with semantic HTML: real headings, landmarks, lists, buttons and links. Give every image appropriate alt text and every form control a label. Make sure everything works with the keyboard alone and that the focused element is clearly visible. Keep enough colour contrast, and do not convey information by colour only. Provide captions for video. Then test by using the page with a keyboard and a screen reader, alongside automated tools.

What is ARIA and when should it be used?

Show answer

ARIA is a set of attributes, such as role, aria-label and aria-expanded, that tell assistive technology what an element is and what state it is in. It is for custom components that have no native equivalent, such as tabs or a combobox, and for conveying dynamic state. It should not be used where a native element already does the job, because ARIA does not add keyboard behaviour, and incorrect ARIA makes a page worse than none.

Key Points to Remember

  • Correct semantic HTML is the foundation of accessibility, often requiring no extra ARIA at all.
  • Prefer native interactive elements (button, a, input) over ARIA-patched generic divs.
  • Every interactive element must be operable via keyboard alone.
  • ARIA attributes like aria-label and aria-expanded fill gaps native HTML can't express, but should be used sparingly.

Practice in the playground

Write and run your own code for this topic, or start from the exercise or an example. Shows a live preview of your HTML, CSS and JavaScript. Your code for each topic is kept in this browser.

Run the examples

Change an input, predict the result, then compare it with the output. Explain why the result changes.

WebNest Studio

Written by

WebNest Studio Engineering Team

Practical lessons from developers working with Java, Python, React, databases and production systems.

Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering