Skip to content

HTML Accessibility

Make web pages accessible with ARIA, alt text, keyboard nav, and semantic markup.

What you'll learn

  • What accessibility (a11y) is and why it is essential
  • How to use alt text, labels, and semantic tags for assistive tech
  • How ARIA attributes fill gaps when HTML alone is not enough
  • How to test keyboard navigation and focus management

Concept

HTML Accessibility

Accessibility (often abbreviated a11y — 11 letters between "a" and "y") means building web pages that everyone can use, including people with visual, motor, cognitive, or auditory disabilities. An accessible page works with screen readers, keyboard-only navigation, voice control, and high-contrast modes. Accessibility is not an optional enhancement — it is a legal requirement in many countries and a moral obligation everywhere.

The Basics: Alt, Labels, and Semantics

The foundation of accessibility is correct HTML. Provide alt text on every image so screen readers can describe it. Connect <label> to every form input. Use semantic tags (<nav>, <main>, <article>) so assistive technology can navigate by landmarks. These three habits alone make a page dramatically more accessible than the average.

ARIA Attributes

ARIA (Accessible Rich Internet Applications) attributes add accessibility information that HTML cannot express on its own. Use role to declare an element's purpose, aria-label for a text alternative, aria-hidden to hide decorative elements from screen readers, and aria-live to announce dynamic updates. But ARIA is a last resort — the first rule of ARIA is "no ARIA is better than bad ARIA." If a native HTML element does the job, use it instead.

Keyboard Navigation

Many users cannot use a mouse. Every interactive element must be reachable with the Tab key and operable with Enter or Space. Links and buttons do this automatically. Custom widgets (like a custom dropdown) need tabindex and key event handlers. Never remove the focus outline (outline: none) without providing a visible alternative — invisible focus states make keyboard navigation impossible.

Testing Accessibility

Test with the keyboard first: unplug your mouse and try to use your page. Then run an automated checker like Lighthouse or axe. Finally, test with a real screen reader (NVDA on Windows, VoiceOver on Mac). Automated tools catch about 30% of issues; the rest need human judgment. Accessibility is a process, not a checkbox.

Example

              <nav aria-label="Main navigation">
  <a href="/">Home</a>
  <a href="/products">Products</a>
</nav>

<main>
  <h1>Welcome to Our Store</h1>
  <img src="banner.jpg" alt="Summer sale — up to 50% off" />

  <button aria-label="Close dialog" onclick="closeDialog()">
    &times;
  </button>

  <div role="alert" aria-live="assertive">
    <!-- Screen readers announce changes here automatically -->
    <p id="status">Item added to cart.</p>
  </div>
</main>
            

aria-label names the nav for screen readers. alt text describes the banner image. The close button has a text label even though it only shows ×. role='alert' with aria-live announces dynamic updates to assistive technology.

Try it

  • HTML ↔ Markdown

    Check that your accessible HTML converts cleanly to Markdown and back.

  • Markdown Previewer

    Preview content to verify heading structure and reading order for screen readers.

Common mistakes

The mistake

Using alt="" on meaningful images or omitting alt entirely.

The fix

Every <img> needs an alt. Use descriptive text for meaningful images. Use alt="" (empty) only for purely decorative images that screen readers should skip.

The mistake

Removing the focus outline with outline: none and no replacement.

The fix

Keyboard users need a visible focus indicator to know where they are. If you remove the default outline, add a custom one (e.g., a box-shadow) that is clearly visible.

Related Cheatsheets

Practice HTML Accessibility

2 exercises

Practice HTML Accessibility

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors