HTML Accessibility (a11y)
Over 1.3 billion people worldwide live with some form of disability. Web accessibility (abbreviated a11y — 11 letters between "a" and "y") ensures your HTML works for everyone — including people who use screen readers, keyboard-only navigation, voice control, or high-contrast displays. In this chapter you'll master the techniques, attributes, and ARIA roles that make HTML truly inclusive — and why it also improves SEO.
alt text for
imagesaria-label,
aria-describedby, aria-hidden
tabindex,
focus management, skip linksWhat is Web Accessibility?
Web accessibility means building websites that anyone can use — regardless of ability. This includes people who are blind or low-vision (using screen readers), deaf (needing captions), motor-impaired (using keyboard or switch devices), or cognitively different (needing clear structure). The international standard is the Web Content Accessibility Guidelines (WCAG), maintained by the W3C. It is built on four core principles:
alt text helps Google
image search. Semantic HTML gives search engines structure. Descriptive link text improves crawlability.
Clear heading hierarchy improves content ranking. Building accessible HTML is building better HTML
for everyone.
Image Alt Text — The Most Important a11y Rule
The alt attribute on <img> is the single most impactful accessibility attribute. Screen
readers read it aloud when the image is encountered. Search engines use it to understand image content. It
is also displayed when the image fails to load.
alt="" — an empty string. Screen
readers then skip it silently. Never omit the alt attribute entirely — without it,
screen readers read the filename aloud (e.g. "img_4827.jpg").alt="Search". For a logo that links home: alt="K2infocom – go to homepage".
<!-- ✅ Good: informative — describes content -->
<img src="classroom.jpg"
alt="Students attending HTML class at K2infocom Vadodara">
<!-- ✅ Good: decorative — empty alt, screen reader skips -->
<img src="divider.svg" alt="" role="presentation">
<!-- ✅ Good: functional — describes what clicking does -->
<a href="/">
<img src="logo.svg" alt="K2infocom — go to homepage">
</a>
<!-- ❌ Bad: missing alt — screen reader reads filename -->
<img src="img4827.jpg">
<!-- ❌ Bad: redundant alt — says "image of" -->
<img src="teacher.jpg" alt="image of a teacher">
ARIA Attributes — Accessible Rich Internet Applications
ARIA (Accessible Rich Internet Applications) is a set of HTML attributes that
add or modify the semantics of elements for assistive technologies. The golden rule:
use native HTML first — only add ARIA when there is no semantic HTML element that conveys
the meaning. A <button> is always better than <div role="button">.
id. More powerful than aria-label when the label is already visible on screen.
aria-hidden="true", the element and all
its children are completely hidden from assistive technologies — useful for decorative
icons or duplicate content that would be confusing if read aloud.polite (waits for idle),
assertive (announces immediately, interrupting). Use for status
messages, errors, countdown timers.
required attribute — but add aria-required="true" when building custom form controls."true" via JavaScript after the user submits or blurs. Pair with aria-describedby pointing to the error message.Landmark Roles — Navigation for Screen Readers
Landmark roles define the major structural regions of a page. Screen
reader users can press a shortcut key to jump directly to any landmark — bypassing all the content between
them. HTML5 semantic elements automatically provide most landmark roles — but you can also use role on <div> elements when
needed.
aria-label to distinguish them (e.g. "Main navigation", "Breadcrumbs").
role="search" on the wrapper around a search form so screen reader users
can jump to it directly.aria-label or aria-labelledby.<form> has an accessible name. Add aria-label="Contact form" to make it a landmark users can jump to.<!-- Semantic HTML provides most roles automatically -->
<header>...</header> <!-- role="banner" -->
<nav aria-label="Main navigation">...</nav>
<!-- role="search" — no native element for this -->
<div role="search">
<label for="search">Search courses</label>
<input type="search" id="search">
<button type="submit">Search</button>
</div>
<main>...</main> <!-- role="main" -->
<aside>...</aside> <!-- role="complementary" -->
<footer>...</footer> <!-- role="contentinfo" -->
Skip Navigation Links
A skip link is a hidden anchor at the very top of the page that lets keyboard users jump directly to the main content — bypassing the navigation that repeats on every page. It is visible only when focused (by pressing Tab as the first action on the page). WCAG 2.4.1 requires this on every page with repeated navigation.
<!-- First element in <body> -- before the nav -->
<a href="#main-content" class="skip-link">
Skip to main content
</a>
<nav>...long navigation...</nav>
<main id="main-content" tabindex="-1">
...page content...
</main>
.skip-link {
position: absolute;
top: -100%; /* hidden off-screen by default */
left: 16px;
z-index: 9999;
padding: 10px 20px;
background: #e44d26;
color: white;
font-size: 15px;
font-weight: 700;
border-radius: 0 0 8px 8px;
text-decoration: none;
transition: top 0.2s;
}
.skip-link:focus {
top: 0; /* visible when focused by Tab key */
outline: 3px solid #fff;
outline-offset: 2px;
}
Colour Contrast
Low contrast text is one of the most common accessibility failures — affecting users with low vision, colour blindness, or anyone reading in bright sunlight. WCAG specifies minimum contrast ratios between text and background colour:
| Content Type | WCAG AA (minimum) | WCAG AAA (enhanced) |
|---|---|---|
| Normal text (below 18pt / 14pt bold) | 4.5 : 1 | 7.0 : 1 |
| Large text (18pt+ or 14pt+ bold) | 3.0 : 1 | 4.5 : 1 |
| UI components & graphical objects | 3.0 : 1 | — |
| Decorative text or logos | No requirement | |
Here are live contrast examples — notice how the failing combinations are hard to read:
Accessible Form Checklist
Forms are the most common source of accessibility failures. Here is a complete checklist with code for each requirement:
<form
aria-label="Course enrolment form"
action="/enroll"
method="POST"
novalidate
>
<!-- 1. Label linked to input via for/id -->
<label for="name">
Full Name
<span aria-hidden="true"> *</span>
<span class="sr-only">(required)</span>
</label>
<!-- 2. Input with hint and validation states -->
<input
type="text"
id="name"
name="name"
required
aria-required="true"
aria-describedby="name-hint name-error"
autocomplete="name"
>
<!-- 3. Visible hint -->
<p id="name-hint">Enter your full legal name as on your ID</p>
<!-- 4. Error message — shown by JS on invalid submit -->
<p
id="name-error"
role="alert"
aria-live="polite"
hidden
>
Please enter your full name.
</p>
<!-- 5. Descriptive submit button -->
<button type="submit">Submit Enrolment</button>
</form>
<!-- Screen reader only helper class (in CSS) -->
<!--
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
white-space: nowrap;
border-width: 0;
}
-->
Common Mistakes — Do's & Don'ts
These are the most frequent accessibility mistakes beginners make:
<!-- Use native button for actions -->
<button type="button"
aria-label="Close menu"
onclick="closeMenu()">
✕
</button>
<!-- Focus ring in CSS -->
button:focus-visible {
outline: 3px solid #e44d26;
outline-offset: 2px;
}
<!-- Descriptive link text -->
<a href="/courses/webdev">
View Web Dev course details
</a>
<!-- div as button — no keyboard access -->
<div onclick="closeMenu()"
class="close-btn">
✕
</div>
<!-- Removing focus ring (keyboard blind) -->
* { outline: none !important; }
<!-- Vague link text -->
<a href="/courses/webdev">
Click here
</a>
Try It Yourself
The editor below contains a fully accessible page demo. Click Open in Editor and press Tab in the preview to test keyboard navigation — watch the skip link appear and focus rings move.
aria-invalid="true" is applied. Fill in valid data —
the aria-live status message announces success.
Quick Check — Chapter 15
Expand each question to check your understanding before moving on to the multiple choice quiz.
alt="" tells screen readers to skip the image
silently — it is marked as decorative and carries no meaningful information. Use it for:
purely decorative images (background textures, divider lines), icons that are accompanied by visible
text labels, and repeated design elements. Never omit the alt attribute entirely — without it, screen readers fall back
to reading the filename (e.g. "img4827.jpg") which is completely meaningless and frustrating. The
difference: alt="" = "skip this", no alt = "read the filename".
aria-label provides a direct text label written
into the attribute value — ideal for elements with no visible text (icon-only buttons, input fields
without visible labels). aria-labelledby points to another element's
id and uses that element's text as the label —
ideal when the label is already visible on screen (linking a dialog to its heading, linking a region to
its <h2>). Prefer aria-labelledby when a visible label exists — it avoids duplicating text
and keeps screen reader and visual labels in sync automatically.
:focus-visible (which only shows for keyboard navigation, not mouse
clicks): :focus-visible { outline: 3px solid #e44d26; outline-offset: 2px; }.
<a> element placed as the very first
element in the body, hidden off-screen by default and visible only when focused. It links to
the id of the main content section. When a keyboard user presses Tab
on page load, the skip link is the first thing focused — pressing Enter jumps focus directly to main
content, bypassing the navigation menu that repeats on every page. WCAG 2.4.1 (Bypass Blocks) requires
that pages with repeated navigation provide a way to bypass it. Without a skip link, keyboard users must
Tab through every navigation item on every page visit.
aria-live="polite" marks a region as a live region
— when its content changes dynamically (via JavaScript), screen readers automatically announce the new
content after the user finishes their current task (waits for idle). Use it for: form
submission success messages, search results updating, loading complete notifications, cart total
updates. aria-live="assertive" interrupts the user immediately — use
only for critical errors or time-sensitive alerts. Without aria-live, screen reader users never know when dynamic content changes.
tabindex value makes an element
focusable programmatically via JavaScript but not in the natural tab order?- Accessibility (a11y) ensures websites work for everyone. The WCAG standard is built on 4 principles: Perceivable, Operable, Understandable, Robust (POUR).
- Alt text: informative images need descriptive alt text; decorative images need
alt=""; never omit the attribute entirely. Functional images describe the action, not the appearance. - Key ARIA attributes:
aria-label(text label for no-text elements),aria-labelledby(references visible label by id),aria-describedby(hints and errors),aria-hidden="true"(hide from assistive tech),aria-expanded,aria-live,aria-invalid. - Landmark roles are provided automatically by semantic HTML:
<header>= banner,<nav>= navigation,<main>= main,<aside>= complementary,<footer>= contentinfo. - Keyboard navigation:
tabindex="0"adds to tab order;tabindex="-1"enables programmatic focus only. Never remove focus outlines — replace with custom:focus-visiblestyles. - Skip links (WCAG 2.4.1 required) let keyboard users jump past navigation.
Colour contrast must be at least 4.5:1 for normal text (WCAG AA). Use the
.sr-onlyCSS class to provide screen-reader-only text without visual impact.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions, and stay updated with new tutorials.