Web Accessibility (A11y)

    Lesson 15 โ€ข Expert Track

    What You'll Learn

    Why accessibility matters (ethics, law, and SEO)
    Semantic HTML: the foundation of accessible pages
    ARIA attributes: aria-label, aria-live, role
    Keyboard navigation and visible focus indicators
    Colour contrast requirements (WCAG standards)
    Accessible forms, images, and interactive elements

    ๐Ÿ’ก Think of It Like This

    Accessibility is like a building with ramps, lifts, and braille signs. Just as physical spaces must be usable by everyone โ€” including wheelchair users and visually impaired people โ€” websites must work for people who use screen readers, keyboard-only navigation, or have colour vision deficiencies. Over 1 billion people worldwide have some form of disability.

    1. Why Accessibility Matters

    ReasonDetails
    ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Ethical15% of the world has a disability. The web should work for everyone.
    โš–๏ธ LegalMany countries require WCAG compliance (ADA in US, EAA in EU).
    ๐Ÿ“ˆ SEOSemantic HTML and alt text improve search engine ranking.
    ๐Ÿ‘ฅ UXAccessible sites are better for everyone โ€” clearer, faster, more usable.

    2. Semantic HTML โ€” The Foundation

    The single most important thing for accessibility: use the right HTML element for the job. Screen readers understand <button>, <nav>, and <main> โ€” but a <div> is meaningless.

    โŒ Don'tโœ… Do
    <div onclick="..."><button>
    <div class="nav"><nav>
    <div class="header"><header>
    <b>Title</b><h1>Title</h1>

    3. Keyboard Navigation & Focus

    Many users navigate with keyboard only (Tab, Enter, Escape). All interactive elements must be focusable with a visible focus indicator.

    /* โœ… Always visible focus ring */ :focus-visible { outline: 3px solid #3b82f6; outline-offset: 2px; } /* โŒ NEVER do this without a replacement */ /* :focus { outline: none; } */

    Accessible Page Demo

    A page with semantic HTML, focus indicators, skip links, and ARIA

    Try it Yourself ยป
    Code Preview
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Accessible Page</title>
      <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
    
        body {
          font-family: system-ui, sans-serif;
          background: #0f172a;
          color: #e5e7eb;
        }
    
        /* Skip link โ€” visible only on focus */
        .skip-link {
          position: absolute;
          top: -60px;
          left: 10px;
          background: #3b82f6;
      
    ...

    4. Colour Contrast (WCAG Standards)

    LevelNormal TextLarge Text (18pt+)
    AA (required)4.5:1 contrast ratio3:1 contrast ratio
    AAA (recommended)7:1 contrast ratio4.5:1 contrast ratio

    ๐Ÿ’ก Pro Tip: Use browser DevTools โ†’ Accessibility panel to check contrast. Chrome shows contrast ratios when you inspect text elements.

    5. Images & Alternative Text

    Image TypeAlt Text RuleExample
    InformativeDescribe what it showsalt="Golden retriever playing fetch"
    DecorativeEmpty alt (not missing!)alt=""
    Functional (logo/icon)Describe the action/purposealt="Company homepage"

    โš ๏ธ Common Mistakes

    • Using divs for buttons โ€” <div onclick="..."> lacks keyboard support, focus management, and screen reader semantics. Use <button>.
    • Removing focus outlines โ€” outline: none without a replacement makes keyboard navigation impossible.
    • Missing alt text โ€” Not the same as alt="" (decorative). Missing alt entirely is an accessibility violation.
    • Low colour contrast โ€” Light gray text on white background fails WCAG. Test every text/background combination.
    • Relying on colour alone โ€” Don't communicate status only with colour (red/green). Add icons, text, or patterns.

    ๐ŸŽ‰ Lesson Complete

    You now understand the essentials of web accessibility:

    • โœ… Use semantic HTML โ€” the #1 accessibility improvement
    • โœ… All interactive elements must be keyboard accessible
    • โœ… Always provide visible focus indicators
    • โœ… Text must meet WCAG contrast ratios (4.5:1 for normal text)
    • โœ… Images need descriptive alt text (or empty alt for decorative)
    • โœ… Label all form inputs with <label>

    Sign up for free to track which lessons you've completed and get learning reminders.

    Previous

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy Policy โ€ข Terms of Service