Building an Accessible Web: Key Features Every Developer Should Implement

Boost your web accessibility with these practical, easy-to-implement features.

Building an Accessible Web: Key Features Every Developer Should Implement

Making websites accessible ensures that individuals of all abilities can easily navigate, understand, and interact with your content, enhancing the overall user experience for everyone.

This blog post will guide you through eleven key accessibility features, providing actionable advice and code snippets to make your web development more inclusive.

Let's dive in.

Semantic HTML

Using semantic HTML helps assistive technologies (like screen readers) understand the structure of your web page, providing users with a clear, consistent experience.

Code Example:

<header>
  <nav aria-label="Main Navigation">
    <a href="#home">Home</a>
    <a href="#services">Services</a>
    <a href="#contact">Contact</a>
  </nav>
</header>
<main>
  <article>
    <h1>Accessibility in Web Development</h1>
    <p>Making the web accessible to everyone.</p>
  </article>
</main>

Using elements like <header>, <nav>, and <article> helps convey meaning and makes the structure understandable for assistive devices.

Keyboard Navigation

Many users rely solely on their keyboard for navigation, so it's essential that interactive elements are accessible using keys like "Tab," "Enter," and "Space."

Code Example:

<button
  onClick={() => alert('Button clicked!')}
  onKeyDown={(e) => {
    if (e.key === 'Enter' || e.key === ' ') {
      alert('Button clicked!');
    }
  }}
>
  Click Me
</button>

This allows users to activate the button with the "Enter" or "Space" keys, ensuring it works for both mouse and keyboard users.

ARIA Attributes

ARIA (Accessible Rich Internet Applications) attributes help define roles and states for non-standard elements, making them accessible to users with disabilities.

Code Example:

<div
  role="button"
  tabIndex={0}
  aria-expanded="false"
  aria-controls="content"
  onClick={() => toggleContent()}
  onKeyDown={(e) => {
    if (e.key === 'Enter' || e.key === ' ') toggleContent();
  }}
>
  Toggle Content
</div>
<div id="content" aria-hidden="true">Here is the expandable content.</div>

ARIA roles like aria-expanded and aria-controls help communicate an element's current state and functionality to assistive technologies.

Alternative Text for Images

Adding alt text to images ensures users relying on screen readers understand the purpose of an image.

Code Example:

<img src="logo.png" alt="Company Logo" />

<!-- Decorative Image -->
<img src="decorative-line.png" alt="" />

Provide descriptive alt text for informative images, and use an empty alt attribute (alt="") for decorative images so they’re skipped by screen readers.

Color Contrast and Text Size

Sufficient contrast between text and background is crucial for readability, particularly for visually impaired users.

Code Example:

body {
  color: #000; /* Dark text */
  background-color: #fff; /* Light background */
}

.large-text {
  font-size: 1.5em; /* Ensures readability */
}

Always ensure good contrast ratios (at least 4.5:1) between text and background, and provide resizable text for better readability.

Link text should be descriptive enough to make sense out of context, helping users understand where the link will take them.

Code Example:

<a href="/accessibility-resources">Learn more about accessibility</a>

Avoid using generic phrases like "Click here," which can be confusing when read out of context by screen readers.

Form Labels and Instructions

Clear labels are essential for users relying on assistive technology to fill out forms accurately.

Code Example:

<form>
  <label htmlFor="email">Email</label>
  <input type="email" id="email" name="email" aria-required="true" />

  <label htmlFor="password">Password</label>
  <input type="password" id="password" name="password" aria-required="true" />

  <button type="submit">Submit</button>
</form>

Use aria-required and appropriate <label> elements to make forms easier to navigate and understand.

Captioning and Transcripts for Media

To accommodate users who are deaf or hard of hearing, provide captions for videos and transcripts for audio content.

Code Example:

<video controls aria-label="Company Overview">
  <source src="overview.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>
<!-- Link to transcript -->
<a href="/overview-transcript">Read the transcript</a>

Adding captions or transcripts makes multimedia content accessible for users who might not be able to hear or see the media.

Skip to Main Content Links

A "Skip to Main Content" link helps users with assistive technologies bypass repetitive content like navigation menus.

Code Example:

<a href="#main-content" class="skip-link">Skip to Main Content</a>

<main id="main-content">
  <h1>Main Content</h1>
  <p>Here is the primary content of the page.</p>
</main>

Place skip links at the top of the page and make them visible when focused, improving the navigation experience.

Responsive Design

Accessible web design should adapt to various screen sizes and devices, especially for users relying on magnification or different input devices.

Code Example:

/* CSS */
@media (max-width: 600px) {
  body {
    font-size: 1.2em;
  }
  .content {
    padding: 10px;
  }
}

Ensuring text and layout adjust for different screen sizes helps users who rely on screen magnification or mobile devices.

Alerts and Notifications

Make dynamic content changes perceivable to users by notifying assistive technologies of updates.

Code Example:

<div role="alert" aria-live="assertive">
  Form submission successful!
</div>

Use role="alert" and aria-live attributes to notify users about dynamic changes, like form submission success messages.

Conclusion

Incorporating these eleven accessibility features into your web development workflow ensures your website is more inclusive and usable for everyone, including individuals with disabilities.

Accessibility is an ongoing effort, but even small changes can have a huge impact on the user experience.

Additional Resources

Did you find this article valuable?

Support Sean Coughlin by becoming a sponsor. Any amount is appreciated!