Skip to content
Tutorials Center
My learning

Topics

Lesson 105 of 122 ยท Accessibility and Best Practices

Accessibility Basics

Learn who accessibility helps, how screen readers read your HTML, and the habits that matter most, from semantic elements and alt text to labels and contrast.

A web page is accessible when people can use it no matter how they see, hear, move or think. Some visitors listen to your page through a screen reader. Others never touch a mouse, zoom the text to 300%, or rely on captions. Good news: most of the work happens in plain HTML, and the habits you have been building in this course already cover a lot of it.

This lesson explains who accessibility helps, how assistive technology understands a page, and the handful of practices that make the biggest difference.

Who accessibility helps

It is easy to picture "accessibility" as a feature for a small group. In reality it helps a very large and varied audience:

  • Vision: people who are blind and use a screen reader, people with low vision who zoom or magnify, and people with color vision deficiencies.
  • Hearing: people who are deaf or hard of hearing and need captions or transcripts.
  • Movement: people who use only a keyboard, a switch device, voice control or eye tracking instead of a mouse or touch screen.
  • Cognition: people with dyslexia, attention difficulties or memory loss, who benefit from clear structure and plain language.

Disabilities can also be temporary (a broken wrist) or situational (bright sunlight on a phone, a noisy train, a baby in one arm). Everyone gets older, too. Building for accessibility means building for all of these people at once.

The standard: WCAG

The Web Content Accessibility Guidelines (WCAG), published by the W3C, are the reference most organizations and many laws point to. The current version is WCAG 2.2. Its success criteria are grouped under four principles, often remembered as POUR:

Principle Meaning
Perceivable People can take in the content: text alternatives, captions, enough contrast.
Operable People can use the controls: keyboard access, enough time, no seizure risks.
Understandable Content and behavior are predictable and readable.
Robust Content works with current and future tools, including assistive technology.

Each criterion has a level: A (the minimum), AA (the usual target for websites) or AAA (the strictest). When someone says a site "meets WCAG", they usually mean level AA.

How assistive technology reads your page

A screen reader does not look at your pixels. The browser builds an accessibility tree from your HTML, a simplified version of the DOM, and assistive technology reads that. For each meaningful element, the tree records a few key facts:

  • Role: what the thing is (button, link, heading level 2, checkbox, list).
  • Name: what it is called ("Add to cart", "Email address").
  • State: its current condition (checked, expanded, disabled).

Native HTML elements fill in these facts for free. A <button> has the role button, its text becomes its name, and it can be reached and pressed with the keyboard. A <div> styled to look like a button has none of that. This is why the first rule of accessibility is simple: use the right element for the job.

Semantic HTML first

Compare two "buttons" below. Both look the same and both respond to a mouse click. Now try them with the keyboard: click in the preview, then press Tab and Enter.

A div pretending vs a real button

The <div> is invisible to the keyboard and is announced as plain text by a screen reader. You could patch it with tabindex, a role and key handlers, but the real <button> gives you all of that in one word. The same thinking applies everywhere:

  • Use <a href> for navigation and <button> for actions (see Links in Depth).
  • Use real lists, tables and headings for lists, tables and headings.
  • Use landmark elements such as <header>, <nav>, <main> and <footer> so people can jump between regions (see Semantic Elements).

Text alternatives for images

Every <img> needs an alt attribute. What goes in it depends on the image's job:

  • Informative image: describe what matters in context. A photo on a recipe page might be alt="Golden loaf of bread cooling on a wire rack".
  • Functional image (inside a link or button): describe the action, not the picture. A magnifying-glass icon in a search button gets alt="Search".
  • Decorative image: use an empty value, alt="", so screen readers skip it. Do not leave alt out entirely: many screen readers then read the file name instead.
HTML
<img src="team-photo.jpg" alt="Our five-person support team outside the office">
<img src="divider-swirl.svg" alt="">

The Images lesson covers writing alt text in more depth, and Captions and Subtitles covers the equivalent for video and audio.

Headings and page structure

Many screen-reader users skim a page by jumping from heading to heading, or from landmark to landmark. A logical outline (one <h1>, then <h2> sections, then <h3> subsections) makes that fast. Choose heading levels for structure, never for font size, as you learned in Headings and Paragraphs.

Give every page a unique, descriptive <title> too. It is the first thing a screen reader announces when the page loads, and it labels the browser tab.

Labels for every form control

A text box without a label is a guessing game. Placeholder text is not a substitute: it disappears as soon as you type, often has weak contrast, and is not reliably announced. Connect a real <label> to each control instead, and say what went wrong in words, not only with a red border.

Unlabeled vs labeled form

Clicking a label focuses its field, which also gives touch users a bigger target. The error message is tied to the field with aria-describedby, so a screen reader reads it along with the label. You will learn about that attribute in the next lesson; labels themselves are covered in Labels, Fieldsets and Legends.

Color and contrast

Text must stand out clearly from its background. WCAG 2.2 level AA asks for a contrast ratio of at least:

  • 4.5:1 for normal text;
  • 3:1 for large text (about 24px, or about 18.5px when bold);
  • 3:1 for the visual parts of controls, such as an input's border, and for meaningful graphics like chart lines.

Also, never use color as the only way to convey information. "Required fields are in red" fails for anyone who cannot tell red apart. Add text, an icon or a pattern as well.

Contrast and color alone

Browser DevTools show the contrast ratio when you inspect text, so you never have to guess. The Colors lesson has more on choosing readable color pairs.

Declare the language

Put a lang attribute on the <html> element. Screen readers use it to pick the right voice and pronunciation, and browsers use it for hyphenation and translation. When a passage switches language, mark that part too:

HTML
<html lang="en">
  ...
  <p>The cafรฉ's motto is <span lang="it">piano piano</span>: slowly, slowly.</p>

Quick checks you can do today

You do not need special software to catch the most common problems:

  1. Unplug the mouse. Can you reach and use everything with Tab, Shift+Tab, Enter and Space? Can you always see where focus is?
  2. Zoom to 200%. Does the content still fit and make sense without horizontal scrolling on a normal screen?
  3. Turn off images or CSS. Does the page still read in a sensible order?
  4. Run an automated checker such as Lighthouse in Chrome DevTools or the axe browser extension.
  5. Try a screen reader: VoiceOver is built into macOS and iOS, Narrator into Windows, TalkBack into Android, and NVDA is free for Windows.

Automated tools catch only part of the picture. They can tell you an image has no alt, but not whether the alt text actually makes sense. Always combine tools with manual testing.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a screen reader actually read?

    The browser turns the DOM into an accessibility tree with roles, names and states. Screen readers present that tree to the user.
  2. 2. An image is purely decorative. What should its alt attribute be?

    An empty alt tells assistive technology to skip the image. A missing alt often makes screen readers announce the file name instead.
  3. 3. Why is a <button> better than a clickable <div> styled as a button?

    Native elements come with focus, keyboard behavior and the right role for free. A div needs all of that rebuilt by hand.
  4. 4. What contrast ratio does WCAG 2.2 level AA require for normal-size body text?

    Normal text needs at least 4.5:1. Large text and the visual parts of controls need 3:1, and 7:1 is the stricter AAA level.

Summary

  • Accessibility helps people with permanent, temporary and situational disabilities, which means nearly everyone.
  • WCAG 2.2 is the reference standard; most sites aim for level AA.
  • Assistive technology reads the accessibility tree: each element's role, name and state.
  • Use native, semantic elements first; they come with keyboard support and the right roles.
  • Give images meaningful alt text (or alt="" when decorative), use a logical heading outline and label every form control.
  • Keep text contrast at 4.5:1 or more, never rely on color alone, and set lang on <html>.

Next up: ARIA Roles, States and Properties.