Adem TONAY @ ademtonay.com

Web Accessibility Tips

Feb 16 · 8min

When navigating the internet, users who rely on screen readers may encounter certain challenges. Therefore, it’s important for web developers to take specific steps to enhance the experience of these users. Here are some key steps web developers should take to ensure a better experience for screen reader users:

Correct HTML Usage

When building web pages, use semantic HTML tags correctly. Use <h1> through <h6> for headings, <ul>, <ol>, <li> for lists, and <section>, <article>, <aside> for content sections.

<h1>Main Heading</h1>
<p>This is a paragraph.</p>
<ul>
    <li>Item 1</li>
    <li>Item 2</li>
</ul>

Alternative Texts

When adding images with the <img> tag, include appropriate alternative text (alt attribute) for each image. This is important for screen readers as they cannot view images.

<img src="image.jpg" alt="A beautiful landscape image">

Labeling Forms

Add <label> tags to form fields to help users understand what they should input. Additionally, you can group form fields using <fieldset> and <legend>.

<label for="username">Username:</label>
<input type="text" id="username" name="username">

Alternatively, you can use the aria-labelledby attribute.

<label id="username-label">Username:</label>
<input type="text" aria-labelledby="username-label">

Using Aria Labels

Use ARIA (Accessible Rich Internet Applications) labels to enhance accessibility for screen reader users, especially for dynamic content and single-page applications.

<div role="navigation">
    <!-- Navigation menu content -->
</div>

For more information on how to use Aria labels, you can refer to the MDN Aria Guides.

sr-only Class

The sr-only class is used for content that is visually hidden but accessible to screen readers. It’s commonly used to hide text accompanying visual elements while keeping it accessible to screen reader users.

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

This CSS code visually hides the content while keeping it accessible to screen readers.

For example, you can use the sr-only class for the alternative text of a button’s icon:

<button>
    <span class="sr-only">More information</span>
    <i class="fas fa-info-circle"></i>
</button>

Or, for describing a link:

<a href="page.html">
  <span class="sr-only">Click for more information</span> Click here
</a>

Wrapping Up

Improving the experience of screen reader users on websites is a crucial responsibility for web developers. By following these guidelines including proper HTML usage, alternative texts, clear and concise texts, link labeling, specifying focus states, utilizing ARIA labels, keyboard accessibility, and continuous testing and feedback, we can create more accessible and user-friendly websites.

>
CC BY-NC-SA 4.0 2021-PRESENT © Adem TONAY