Menu
CoddyTech

HTML Accessibility Interview Questions

Labels, ARIA, keyboard support, focus and live regions, now standard in front end interviews.

10 questions
  1. What is web accessibility, and how does HTML help?

    Web accessibility (a11y) means people with disabilities can use the site, whether they use a screen reader, only a keyboard, or have low vision. Most of it is correct HTML: semantic elements, alt text, labels on inputs, lang on <html>, and keyboard access with visible focus. The standard is WCAG.

  2. Why should you set the lang attribute on <html>?

    lang tells browsers and assistive technology the page's language, so screen readers pick the right pronunciation and browsers offer translation.

    <html lang="en">
    ...
    <p>The Hindi word <span lang="hi">नमस्ते</span> means hello.</p>
    

    Without it, an English screen reader may read a Hindi page with English pronunciation. Values are language codes with an optional region: en, hi, en-IN. See the lang attribute page.

  3. What is ARIA, and when should you use it?

    ARIA attributes (role, aria-label, aria-expanded, aria-live) tell assistive technology what a custom widget is and what state it is in. Use them only when no native element does the job.

    <!-- Good: native button, no ARIA needed -->
    <button>Save</button>
    
    <!-- ARIA describes state that HTML cannot express -->
    <button aria-expanded="false" aria-controls="menu">Menu</button>
    

    The trap: ARIA changes what is announced, never behavior. role="button" does not make a div focusable or usable from the keyboard.

  4. Why is <div onclick> not a good replacement for <button>?

    A div with a click handler works only with a mouse: it is not in the Tab order, Enter and Space do nothing, and screen readers do not announce a button.

    HTML
    <!DOCTYPE html>
    <style>
      .fake { display: inline-block; padding: 4px 10px; background: #e2e8f0; cursor: pointer; }
    </style>
    <button onclick="count('a')">Real button</button>
    <div class="fake" onclick="count('b')">Fake button</div>
    <p>Real: <span id="a">0</span>, fake: <span id="b">0</span>. Now try them with Tab and Enter.</p>
    <script>
      function count(id) {
        const el = document.getElementById(id);
        el.textContent = Number(el.textContent) + 1;
      }
    </script>

    Matching <button> takes role="button", tabindex="0", key handlers and focus styles. A control that navigates should be an <a href>.

  5. What is the difference between aria-label, aria-labelledby and aria-describedby?

    aria-label names an element with a string, aria-labelledby takes the name from other elements by id, and aria-describedby adds a description read after the name.

    <button aria-label="Close dialog">×</button>
    
    <h2 id="billing">Billing address</h2>
    <section aria-labelledby="billing">...</section>
    
    <input id="pw" type="password" aria-describedby="pw-hint">
    <p id="pw-hint">At least 12 characters.</p>
    

    aria-labelledby beats aria-label, which beats the native label. Put hints and errors in aria-describedby so they are heard on focus.

  6. What do tabindex="0", tabindex="-1" and a positive tabindex do?

    tabindex="0" adds an element to the Tab order at its document position. tabindex="-1" makes it focusable from script (el.focus()) but not with Tab, which suits a heading you move focus to. A positive value jumps ahead of everything else.

    <div role="button" tabindex="0">Custom control</div>
    <h2 id="results" tabindex="-1">Results</h2>  <!-- focused by script after a search -->
    

    Avoid positive values: the Tab order stops following the visual order.

  7. How do you announce dynamic changes to screen reader users?

    Put the changing text in a live region: aria-live="polite" waits for a pause, aria-live="assertive" interrupts. role="status" and role="alert" are the same two.

    HTML
    <!DOCTYPE html>
    <button id="save">Save</button>
    <p role="status" id="status"></p>
    <script>
      document.getElementById('save').onclick = () => {
        document.getElementById('status').textContent = 'Saved at ' + new Date().toLocaleTimeString();
      };
    </script>

    The trap: the region must be in the DOM before its text changes; an element inserted with the message already inside is often not announced.

  8. How do you test a page for accessibility?

    Combine automated checks with manual testing, because tools catch only part of the problems.

    1. Automated: Lighthouse or axe, also in CI.
    2. Keyboard: every control reachable with Tab, focus visible, no trap.
    3. Screen reader: NVDA, VoiceOver or TalkBack.
    4. Zoom and contrast: 200% zoom, text contrast at least 4.5:1, or 3:1 for large text (WCAG AA).
  9. How do you make a data table accessible?

    Use real table markup: a <caption> that names the table, <th> for header cells with scope="col" or scope="row", and <thead> and <tbody>. A screen reader then announces each cell with its row and column headers instead of a stream of numbers.

    HTML
    <table>
      <caption>Test scores</caption>
      <thead>
        <tr><th scope="col">Student</th><th scope="col">Math</th><th scope="col">Science</th></tr>
      </thead>
      <tbody>
        <tr><th scope="row">Asha</th><td>92</td><td>88</td></tr>
        <tr><th scope="row">Ravi</th><td>79</td><td>95</td></tr>
      </tbody>
    </table>

    For headers that span several levels, link cells to them with headers and id. Never use a table for layout. More in HTML tables.

Coddy programming languages illustration

Learn to code with Coddy

Get started