DevAcademy
LearnHTMLAccessibility
AdvancedHTML

Accessibility

Learn how to build inclusive HTML pages using semantic markup, alt text, labels, and ARIA attributes.

Reading Time

18 min

Lesson

Lesson 27 of 27

What is Web Accessibility?

Accessibility (often abbreviated a11y) means building pages that people with disabilities — visual, auditory, motor, or cognitive — can use effectively, often with the help of assistive technology like screen readers.

Semantic HTML is the Foundation

The single biggest accessibility win is using the right semantic element for the job. Native elements like <button>, <a>, and <nav> come with built-in keyboard support and screen reader behavior for free.

Semantic vs Non-Semantic Buttons

<!-- Accessible: keyboard focusable, announced as a button -->
<button onclick="submitForm()">Submit</button>

<!-- Inaccessible: no keyboard support, no button semantics -->
<div onclick="submitForm()">Submit</div>
Output

Accessibility Fundamentals

  • Every image has meaningful alt text (or alt="" if decorative).
  • Every form input has an associated <label>.
  • Heading levels follow a logical order (h1 → h2 → h3).
  • Interactive elements are reachable and usable with a keyboard alone.
  • Color is never the only way information is conveyed.
  • Sufficient color contrast between text and background.

ARIA Attributes

ARIA (Accessible Rich Internet Applications) attributes add extra information for assistive technology when semantic HTML alone isn’t enough — typically for custom, JavaScript-driven widgets.

Common ARIA Attributes

<button aria-label="Close dialog">&times;</button>

<div role="alert">Your changes have been saved.</div>

<input type="text" aria-describedby="password-hint" />
<p id="password-hint">Must be at least 8 characters.</p>
Output

Useful ARIA Attributes

AttributePurpose
aria-labelProvides an accessible name when there is no visible text
aria-labelledbyPoints to another element that labels this one
aria-describedbyPoints to an element with additional descriptive text
aria-hiddenHides purely decorative content from assistive technology
roleOverrides or clarifies the semantic role of an element

The First Rule of ARIA

No ARIA is better than bad ARIA. Always prefer a native semantic element over adding ARIA attributes to a generic <div> — ARIA should fill gaps, not replace semantics you could get for free.

Keyboard Navigation

Many users navigate exclusively with a keyboard. Every interactive element must be reachable with Tab and operable with Enter or Space, in a logical order that matches the visual layout.

Best Practice

Build with semantic HTML first, test your pages using only a keyboard, and run an automated checker (like Lighthouse or axe) to catch common accessibility issues early.

Summary

Accessibility is not an afterthought — it starts with the semantic HTML choices you make on day one. Combined with proper labels, alt text, and ARIA where needed, it ensures your pages work for everyone.

Interview Questions

Quick Quiz

1. What is the biggest accessibility win you can make?

2. What is the "first rule of ARIA"?

3. Why must interactive elements be operable with a keyboard alone?

Previous