CHAPTER 50 · HTML

Accessibility basics: make meaning and actions available to more people

Bring together headings, labels, text alternatives and keyboard use. Build useful native HTML and review real behaviour instead of relying on appearance alone.

Download example files (ZIP)

Start with people using the page

A student may use a keyboard instead of a mouse, enlarge text, listen through a screen reader or read slowly while learning English. Accessibility means making content and actions usable by people with different disabilities and access needs. The same choices often help other readers too.

A screen reader is a tool that presents interface information through speech or braille. It needs meaningful structure and names, not just a page that looks tidy. Accessibility is part of building the page, rather than a final colour setting to add after everything else.

Use native elements for their actual jobs

Use a link with href to go somewhere, a button to perform an action, a heading to describe a section and a label to name a form control. Native elements supply behaviour that a styled div does not. A div that looks like a button does not automatically gain keyboard handling, a name or an appropriate role.

Keep heading levels logical. Make link wording describe the destination rather than repeating Click here. A useful title, document language and main content region help orient readers. Choosing semantic tags is a foundation, not proof that every interaction is accessible.

Keyboard use: follow a visible route

Tab normally moves through interactive elements in document order; Shift+Tab goes backward. Enter activates links and native buttons; Space also activates a native button. Some controls, such as radio groups and selects, have additional native key behaviour.

Keep the focus indicator visible. Do not add positive tabindex values to patch a confusing source order, and do not add tabindex=0 to every paragraph. Ordinary text can be read without making it an extra Tab stop. Test whether a reader can reach controls, operate them and leave them again without a trap.

Provide a skip route past repeated navigation

The session example has a visible Skip to main content link before its page navigation. It points to main-content. The main has tabindex=-1 so it can receive focus without being added to the normal Tab sequence. This helps bypass repeated links when needed.

The target must exist and its id must match the fragment. Check the actual keyboard result in a saved page. A link that merely changes the address but leaves people at the wrong place does not satisfy the intended route.

Give images and graphics a text purpose

Informative images need text alternatives appropriate to their purpose. A purely decorative image can use alt="" when it adds no information; omitting alt is different. A linked image needs an accessible name that describes its link purpose. Complex diagrams and canvas drawings need their important meaning available in text too.

Do not communicate a required answer or an error only through a colour. Explain it in words. Captions, transcripts and other alternatives for media should preserve the relevant information rather than simply saying video here.

Label fields and explain rules before errors

A label for must match the control id. Keep the visible label, not just a placeholder that disappears while typing. Put format or privacy instructions near the field and use aria-describedby when those words should be associated with it. Required should be clear in visible wording as well as markup.

In the form example, the alias instruction is permanently visible and the field points to it. Native validation can identify empty required answers during ordinary submission. It does not replace clear instructions, trustworthy receiving-side checks or suitable custom error handling when a real application adds more complex rules.

Use ARIA to support meaning, not invent behaviour

ARIA stands for Accessible Rich Internet Applications. Its attributes can supply names, descriptions or state information for assistive tools. They do not automatically add click handlers, keyboard support or validation. Prefer a correct native element before adding roles. Aria-label can override the name people hear; do not use it casually to replace a clear visible label with different wording.

Do not hide a focusable control with aria-hidden. That can leave keyboard users on a control that assistive tools cannot describe. We will examine names, descriptions and states more deeply in the next accessibility lessons.

Review content, presentation and interaction together

Read the page in order, test the keyboard, enlarge text and check small-screen wrapping. Verify labels, alternatives and any dynamic updates. Contrast and readability matter alongside HTML structure. Automated tools can find some missing names or invalid combinations, but they cannot judge every explanation or prove that a task is usable.

These examples demonstrate useful foundations, not a certificate of accessibility compliance. Real products need broader testing, including assistive technology and, where possible, feedback from people who use it. Keep your check results specific about what you actually tested.

Follow the idea

Review the reader’s route
  1. 1Meaningful elements and headings
  2. 2Names and instructions
  3. 3Keyboard access and visible focus
  4. 4Text alternatives and actual testing

A tidy appearance or a single automated check is not a complete review.

Complete program: accessible-session.html

Save this as accessible-session.html. Open it in your browser.

accessible-session.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>A Readable Session Page</title>

    <style>
      body {
        color: #202c3a;
        background: #fff;
        font-family: Arial, sans-serif;
        line-height: 1.6;
        margin: 1rem;
      }
      a {
        color: #174a94;
      }
      a:focus-visible {
        outline: 3px solid #174a94;
        outline-offset: 3px;
      }
      img {
        max-width: 100%;
        height: auto;
      }
    </style>
  </head>
  <body>
    <h1>A practice session everyone can follow</h1>
    <p><a href="#main-content">Skip to main content</a></p>
    <nav aria-label="Page sections">
      <a href="#about">About the session</a> | <a href="#session">Session details</a>
    </nav>
    <main id="main-content" tabindex="-1">
      <section id="about">
        <h2>About the session</h2>
        <p>Bring one saved HTML page and explain it to a partner.</p>
      </section>
      <section id="session">
        <h2>Session details</h2>
        <p>This fictional session meets in Room B-204. Keep your own notebook with you.</p>
        <img
          src="images/study-desk.svg"
          alt="An open notebook beside a laptop on a study desk"
          width="360"
          height="220"
        />
      </section>
    </main>
  </body>
</html>
Browser previewDocument title: A Readable Session Page

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.

Expected result: a session page with a useful title, explicit language, descriptive navigation, two topic headings and an informative image alternative. In a saved file, the skip link reaches and focuses main-content without turning main into an ordinary Tab stop.

Complete program: accessible-question.html

Save this as accessible-question.html. Open it in your browser.

accessible-question.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>A Clearly Labelled Practice Form</title>

    <style>
      body {
        color: #202c3a;
        background: #fff;
        font-family: Arial, sans-serif;
        line-height: 1.6;
        margin: 1rem;
      }
      input,
      textarea {
        max-width: 100%;
        box-sizing: border-box;
      }
      button:focus-visible,
      input:focus-visible,
      textarea:focus-visible {
        outline: 3px solid #174a94;
        outline-offset: 3px;
      }
    </style>
  </head>
  <body>
    <h1>Ask a fictional practice question</h1>
    <main>
      <p>
        This is an HTML exercise, not a message service. Keep form-result.html from Chapter 31
        beside this file.
      </p>
      <form action="form-result.html" method="get">
        <fieldset>
          <legend>Practice question</legend>
          <p><label for="practice-alias">Practice alias (required)</label></p>
          <p id="alias-help">
            Use an invented name. Do not enter private information in this URL-based exercise.
          </p>
          <p>
            <input
              type="text"
              id="practice-alias"
              name="alias"
              required
              maxlength="30"
              aria-describedby="alias-help"
            />
          </p>
          <p>
            <label for="practice-question">Your question (required, up to 120 characters)</label>
          </p>
          <p>
            <textarea
              id="practice-question"
              name="question"
              required
              maxlength="120"
              rows="3"
              cols="28"
            ></textarea>
          </p>
        </fieldset>
        <button type="submit">Inspect practice values</button>
      </form>
    </main>
  </body>
</html>
Browser previewDocument title: A Clearly Labelled Practice Form

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.

Expected result: a clearly grouped form with permanent labels and visible instructions. Clicking each label targets its field. Ordinary validated submission rejects missing required answers. Valid fictional values reach the static result page; no question is delivered or stored. The tutorial preview disables submission.

Problem and solution

Problem: a field has only a placeholder and becomes hard to identify once someone starts typing.

Solution: add a persistent visible label connected through for and id. Keep any format instruction as separate visible text and associate it when helpful.

Common mistakes and useful tips

  • Do not build ordinary buttons from clickable divs.
  • Do not remove focus outlines for appearance.
  • Do not make every paragraph a Tab stop.
  • Placeholder is not a substitute for a label.
  • Do not hide interactive controls from assistive tools.
  • Do not call one automated test a complete accessibility review.

Practice questions

  1. Why use a native button for an action?
  2. Which key normally moves to the next interactive control?
  3. What does the skip link target?
  4. How is decorative alt="" different from omitted alt?
  5. Does ARIA automatically add keyboard behaviour?
  6. Save both examples. Test the skip link, form labels, Tab route and required checks using invented values. Record one result for each.
Check your practice answers
  1. It supplies appropriate native semantics and keyboard behaviour rather than relying on a decorative div.
  2. Tab; Shift+Tab moves backward.
  3. Main-content, the id of the main region.
  4. An empty alternative intentionally marks a decorative image. Omitted alt does not express that intention.
  5. No. It describes meaning or state, not the missing interaction logic.
  6. The skip route should focus main, labels should target their controls, native controls should be reachable, and empty required fields should block ordinary submission. State only the behaviours you actually observed.

Interview questions

What is an accessible name?

The name assistive tools use to identify an interface element, often coming from visible button text or a properly associated label.

Why is semantic HTML not the whole task?

Correct elements help, but wording, alternatives, focus behaviour, contrast and dynamic interactions can still create barriers.

How do label and aria-describedby differ?

A label identifies the control. Aria-describedby associates extra explanatory text; it does not replace the control name.

Can an automated checker prove full accessibility?

No. It can identify some detectable issues. Manual interaction, content review and appropriate assistive-technology testing are still necessary.

Quick revision

  • Choose native elements and clear names.
  • Keep a logical visible keyboard route.
  • Provide meaningful text alternatives and instructions.
  • Combine automated checks with real use.