A Developer’s Guide to WCAG 2.1: Making Your Website Accessible

Trushang SutharTrushang Suthar
4 min read

What is WCAG 2.1?

The Web Content Accessibility Guidelines (WCAG) 2.1 are an international set of standards aimed at making web content accessible to all users, regardless of their abilities or the devices they use.

These guidelines are built on four principles, often abbreviated as POUR:

  1. Perceivable: Content must be presented in a way that users can perceive (e.g., adding alt text for images).

  2. Operable: Users must be able to interact with the content (e.g., navigating via keyboard).

  3. Understandable: Information and navigation must be clear and easy to use (e.g., providing error messages).

  4. Robust: Content must work well with assistive technologies like screen readers.

WCAG compliance is categorized into three levels:

  • Level A: Basic accessibility requirements.

  • Level AA: Targets the largest audience and is often the legal standard.

  • Level AAA: The highest and most strict level, often optional.


Key WCAG 2.1 Requirements (with Examples)

Here’s how you can implement WCAG 2.1 in your web application, along with HTML examples:

1. Add Alternative Text for Images
Provide descriptive alt text so screen readers can describe images to visually impaired users.

<img src="example.jpg" alt="A painting of a sunset on the beach">

2. Ensure Forms Have Labels
Use the <label> tag to associate labels with form inputs.

<form>
  <label for="name">Enter your name:</label>
  <input type="text" id="name" name="name" required>
</form>

3. Maintain a Minimum Contrast Ratio
Ensure a contrast ratio of at least 4.5:1 between text and background.

<p style="color: #000000; background-color: #ffffff;">Readable text with proper contrast.</p>

4. Enable Keyboard Navigation
All interactive elements should be accessible via keyboard (e.g., using Tab and Enter). Avoid using <div> or <span> for interactive elements.

<button onclick="submitForm()">Submit</button>

5. Make Links Descriptive
Replace vague link text like “Click here” with meaningful descriptions.

<a href="/contact-us">Contact Us for more information</a>

6. Structure Tables Properly
Use semantic tags like <thead>, <tbody>, and <th> to make tables understandable.

<table>
  <thead>
    <tr>
      <th>Item</th>
      <th>Price</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Painting</td>
      <td>$500</td>
      <td>Available</td>
    </tr>
  </tbody>
</table>

7. Add Skip Links for Better Navigation
Help keyboard users skip repetitive navigation links.

<a href="#main-content" class="skip-link">Skip to Main Content</a>
<div id="main-content">
  <h1>Welcome to Our Website</h1>
</div>

8. Use ARIA for Dynamic Content
ARIA attributes help assistive technologies understand and announce dynamic content.

<div role="alert" aria-live="polite">
  Your bid has been successfully placed!
</div>

How to Check Your Website for WCAG Compliance

1. Automated Testing Tools

  • WAVE: Browser extension for accessibility checks.

  • Lighthouse: Built into Chrome DevTools for audits.

  • axe Accessibility: Chrome and Firefox extension for in-depth analysis.

2. Manual Testing

  • Keyboard Navigation: Use Tab and Enter to navigate your site.

  • Screen Reader Testing: Test your site with tools like NVDA, JAWS, or VoiceOver to ensure content is announced correctly.

3. Visual Accessibility

  • Test colour contrast using tools like Contrast Checker by WebAIM.

  • Zoom in up to 200% and ensure your site layout doesn’t break.


Tools for WCAG 2.1 Compliance

ToolPurposeLink
WAVEIdentify accessibility issueswave.webaim.org
axe AccessibilityBrowser extension for accessibility auditsDeque Axe
Contrast CheckerTest text-to-background contrastContrast Checker
NVDAFree screen reader for WindowsNVDA
VoiceOverBuilt-in screen reader for macOS and iOSN/A

Action Plan for Developers

  1. Understand Requirements: Familiarize yourself with WCAG 2.1 guidelines, focusing on Level AA compliance.

  2. Audit Your Website: Use tools like WAVE or Lighthouse to identify and prioritize issues.

  3. Fix High-Priority Issues:

    • Add alt text, form labels, and proper colour contrast.

    • Ensure keyboard accessibility and descriptive links.

  4. Manual Testing: Perform keyboard navigation and screen reader tests.

  5. Retest and Validate: After making changes, retest your site with automated tools and real users if possible.


Conclusion

WCAG 2.1 compliance isn’t just about meeting legal requirements; it’s about making your website inclusive and user-friendly for everyone. By following this guide and leveraging the tools and techniques outlined, your team can ensure your web application is accessible to a wider audience.

Accessibility is a journey, not a destination—start yours today!

0
Subscribe to my newsletter

Read articles from Trushang Suthar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Trushang Suthar
Trushang Suthar

Code is like a puzzle—sometimes you just need to step back, take a breath, and the solution clicks.