Fix 85% of your Web Accessibility issues in 5 easy steps
Tags: a11y, webdev, html, css
Published: 2019-05-02 18:46:55

---
title: Fix 85% of your Web Accessibility issues in 5 easy steps
published: true
description: Five easy to implement tips that will improve websites' accessibility.
tags: a11y,webdev,html,css
canonical_url: https://alvaromontoro.com/blog/67834/fix-85-of-your-web-accessibility-issues-in-5-easy-steps
---

In a previous post, we saw the [importance of Web Accessibility](https://dev.to/alvaromontoro/a-case-for-web-accessibility-d4i) and mentioned [The WebAIM Million](https://webaim.org/projects/million/), an analysis by [WebAIM](https://webaim.org/) on the current state of Web Accessibility of 1 million popular pages.

The results were devastating: the analyzed home sites averaged almost 60 errors each, and the percentage of _clean_ sites was less than 3%. But, there was a silver lining: most of the errors could be grouped into just a handful of categories. Out of a total of 59.6 million errors, 52.1 million were caused by only five easy-to-prevent problems:

- [36 million were instances of text with insufficient contrast](https://webaim.org/projects/million/#contrast).
- [12.3 million were images without an alterntive text](https://webaim.org/projects/million/#alttext).
- [2 million were inputs without a corresponding label](https://webaim.org/projects/million/#labels).
- [1.3 million were ambiguous or empty links](https://webaim.org/projects/million/#links).
- [0.5 million were unordered headings](https://webaim.org/projects/million/#headings).

Correcting these five issue types would fix most of the Accessibility problems detected.


## The 5 easy steps

### 1. Increase text color contrast

Poor text contrast was the most common mistake according to the WebAIM report. On average, the analyzed home pages contained 36 issues with insufficient contrast between text and its background.

<figure id="demo-contrast" class="demo">
  ![Examples of text contrast in a button](https://thepracticaldev.s3.amazonaws.com/i/fup4n1sm04xzkpw3rskq.png)
  <figcaption>The difference between valid and invalid color contrast is sometimes subtle.</figcaption>
</figure>

For me, this may be the most limiting requirement	(at least creativity-wise), as many times I find an interesting color palette that I end up discarding because it doesn't meet the <abbr title="Web Content Accessibility Guidelines">WCAG</abbr> specifications. One option is following the less restrictive Level AA level criteria as [it is not possible to satisfy all Level AAA success criteria for some content](https://www.w3.org/TR/UNDERSTANDING-WCAG20/conformance.html#uc-conf-req1-head) anyway.

WebAIM has a really nice [tool to check color contrast](https://webaim.org/resources/contrastchecker/), and you can find many other tools online. Actually, it is really easy to implement your own one. It requires some math, but nothing fancy, and it can be a great learning experience. For example, I [developed a contrast checker myself](https://codepen.io/alvaromontoro/pen/YgpWZG) in order to test RGB colors since all the checkers I found online worked with HEX values only.

### 2. Add alternative text to images

Adding alternative text to images is one of the main pillars and [basic principles of Web Accessibility](https://webaim.org/techniques/alttext/). Yet it is one of the most common problems in almost every website, even when the `alt` attribute is required in images.

```html
<img src="guernica.jpg" alt="Guernica painting by Pablo Picasso" />
```
    
Although it seems as simple as adding the `alt` attribute with a description to the `<img>` tag, the alternative text may require a little bit of thought. What is the role of the image? What is the text surrounding it? We may not want to ignore the image (adding an `alt=""`), and we don't want to have screen readers repeating the same information twice.

<table>
  <tr>
    <td>
      <img src="https://i.imgur.com/1RYgSEfm.jpg" />
    </td>
    <td>
      <p><code>alt="Guernica painting by Pablo Picasso"</code></p>
      <p><code>alt="Guernica: a large oil painting by Spanish artist Pablo Picasso completed in June 1937"</code></p>
      <p><code>alt=""</code></p>
    </td>
  </tr>
</table>
<figcaption>Any of the <code>alt</code> on the right could work for the image, it will depend on the context</figcaption>

And one more thing to consider: **if the image is used as a <abbr title="call to action">CTA</abbr>, the `alt` should be a description of the action** to be taken and not of the image! Users may want to know that the image is a printer, but what they really want to know is that if they click on it, the document will be printed.


### 3. Label form elements

Labels present many benefits such as: (1) they help identify & provide additional information about the field; (2) when clicked they will focus on the linked form element; and (3) they are [simple to implement](https://webaim.org/techniques/forms/advanced). You just need to wrap the text with a `<label>` tag and use the `for` attribute to point to the element's id:

```html
<label for="username">Username:</label>
<input id="username" type="text" name="user">
<label for="password">Password:</label>
<input id="password" type="password" name="pass">
```

Sometimes there may be _tricky situations_ in which inputs may not have a specific label for each of them (e.g. a table with rows that allow edition, or a label that should apply to multiple fields). In these cases, you may use the attribute `aria-labelledby` to point to the element that will serve as a label:

```html
<table>
  <thead>
    <tr>
      <th id="namelabel">Name</th>
      <th id="addresslabel">Address</th>
      <th id="agelabel">Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input aria-labelledby="namelabel" name="name" /></td>
      <td><input aria-labelledby="addresslabel" name="address" /></td>
      <td><input aria-labelledby="agelabel" name="age" /></td>
    </tr>
    ...
  </tbody>
</table>
```

If you have a form or a component that includes form elements such as input fields or radio buttons, don't forget to add a label for the different form elements or add a `aria-labelledby` attribute.

### 4. Add meaning to links

How many times have you found a website or blog with summaries of the posts and links asking to "Read more"? While that is a description of the action that the user will perform, it [doesn't really provide actual meaning to the link](https://webaim.org/techniques/hypertext/link_text). Are we going to be reading more about elephants, web programming, or brain surgery? Read more about what?

<table>
  <tr>
    <td>
      Don't do these things...<br/>
      <a href="https://codepen.io/alvaromontoro/post/a-case-for-web-accessibility">Read more</a>
    </td>
    <td>
      Do these things instead...<br/>
      <a href="https://codepen.io/alvaromontoro/post/a-case-for-web-accessibility">Read more about Web Accessibility</a><br/>
    </td>
  </tr>
</table>
<figcaption>One of these links provides actual information about the linked content</figcaption>

Now some may say: "_But having a long meaningful link breaks the way in which our site is presented! There's only space for a 'Read more' caption!_" And for them there is an alternative: use `aria-label` in your links: 

```html
<a href="#" aria-label="Read more about Web Accessibility">
  Read more
</a>
```

[Modern screen readers will read the `aria-label` instead of the anchor text](https://www.deque.com/blog/text-links-practices-screen-readers/), so you could potentially leave your short link caption while providing a meaningful and accessible text.



### 5. Organize content correctly

The content on each page should be [structured semantically and organized correctly](https://webaim.org/techniques/semanticstructure/), using the right headings in an orderly way. This may sound like a no-brainer, but it is a really common mistake: over half of the analyzed home pages presented this issue.

Screen readers allow users to jump from heading to heading. A poorly organized document will resemble a Choose Your Own Adventure book for them! And the disorganization is also confusing for the rest of us as well as for website crawlers.

<table class="demo">
  <tr>
    <td>
      <h1>Heading 1</h1>
      <h3>Heading 3</h3>
      <h2>Heading 2</h2>
      <h4>Heading 4</h4>
    </td>
    <td>
      <h1>Heading 1</h1>
      <h2>Heading 2</h2>
      <h3>Heading 3</h3>
      <h4>Heading 4</h4>
    </td>
  </tr>
</table>
<figcaption>Your document should be organized like the right column, never like the left one</figcaption>

Also, don't forget to use the proper semantic tags; it is important to use headings (`<h1>`, `<h2>`, etc.) instead of styling other elements to look like a title. They may be similar visually, but not all users rely on their vision.


## Conclusion

The fact that 87% of the Web Accessibility problems found on the WebAIM analysis were really _low hanging fruit_ errors may seem like great news, but we need to take these results with a grain of salt: the analyzed pages were just home pages, which normally don't include complex components subject to more complex accessibility issues.

Also, claiming that 85% of all the accessibility issues could be fixed with the 5 steps above is a bit of a stretch. (Sorry for the click-baity title.) Although, chances are that the actual percentage is not that far off from reality ([which would make good the old 80/20 rule in computing](https://en.wikipedia.org/wiki/Pareto_principle#In_computing)).

The main lesson to take away would be that **improving Web Accessibility may be challenging, but it is not as complicated as it seems,** and every improvement, even the tiniest one, counts.