HTML Β· Chapter 43 of 45

HTML Accessibility

Web accessibility (a11y) ensures people with disabilities can use websites, including those relying on screen readers, keyboard-only navigation, or assistive devices. Using semantic HTML is the single biggest step toward accessibility.

ARIA (Accessible Rich Internet Applications) attributes like aria-label and role can supplement semantics when native HTML isn't enough, but should never replace proper semantic elements when one is available.

Syntax
<button aria-label="Close">Γ—</button>

Semantic HTML first

Native elements like <button> and <nav> come with built-in keyboard support and screen reader announcements for free β€” using a styled <div> instead loses all of that.

ARIA and alt text

aria-label provides an accessible name when visible text is insufficient. alt text on images and proper form labels are essential baseline requirements.

Example 1 (html)
<button aria-label="Close dialog">&times;</button>
Output
(screen readers announce 'Close dialog' button)

aria-label gives an accessible name when the visible symbol alone isn't descriptive.

Example 2 (html)
<img src="chart.png" alt="Sales increased 20% in Q3">
Output
(screen readers describe the chart's meaning)

Descriptive alt text conveys the same information visually and non-visually.

Key points

  • Semantic HTML provides accessibility features by default.
  • ARIA attributes supplement, not replace, semantic HTML.
  • alt text and form labels are essential accessibility basics.
  • Keyboard navigation should work without requiring a mouse.
πŸ’‘ Note: The 'first rule of ARIA' is: don't use ARIA if a native HTML element already does the job.

πŸ“ Quick Quiz

1. What should you prefer over ARIA when possible?

2. What does aria-label provide?

3. Why should sites support keyboard-only navigation?