Web Accessibility: 10 Quick Fixes for Your Website

Ten quick accessibility fixes with code to copy: alt text, labels, real buttons, headings, link text, contrast, focus and tap targets, each matched to WCAG 2.2.

AAyim Nelson27 Nov 202610 min read2

Picture the people visiting your website. One uses a screen reader that reads the page aloud. One can't use a mouse and moves around with the Tab key. One has zoomed the page to twice its size. One is on a cheap phone, in bright sun, on a bumpy trotro. If your site works for all of them, it works better for everyone else too.

That is what web accessibility means: building pages that everyone can use. The good news is that many of the most common problems take minutes to fix. Here are ten quick fixes, each with the code to copy and the WCAG rule it helps you meet.

A word about WCAG

WCAG (Web Content Accessibility Guidelines) is the world's accessibility standard, and the current version is WCAG 2.2. Its rules are called success criteria, each with a number such as 1.4.3 and a level: A (the basics), AA (the level most laws and companies ask for) and AAA (the highest). The fixes below are all about meeting A and AA.

1. Set the page language and a useful title

Two tiny lines make a big difference. The lang attribute tells screen readers which language and voice to use (WCAG 3.1.1). The <title> is the first thing a screen reader says when the page opens, and the name in browser tabs (WCAG 2.4.2):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Checkout - Kejetia Online Market</title>
</head>

Put the specific part first ("Checkout") and the site name after, so people with many tabs open hear the useful bit straight away.

2. Give every image the right alt text

Screen readers can't see pictures; they read the alt text instead (WCAG 1.1.1). Describe what the image tells the visitor, briefly. If an image is only decoration, use an empty alt="" so it's skipped:

<img src="kente.jpg" alt="Hand-woven kente cloth in gold, green and red, GHS 450">

<img src="divider.png" alt="">

Leaving alt out completely is the worst choice: many screen readers then read the file name aloud, such as "IMG underscore 2041 dot JPG".

3. Label every form field

Placeholder text inside a box is not a label. It disappears as soon as you type, it's usually pale grey and hard to read, and some assistive tools ignore it. Give every input a visible <label>, linked to it with for and id (WCAG 1.3.1 and 3.3.2):

<!-- Before: no label -->
<input type="tel" placeholder="Phone number">

<!-- After -->
<label for="phone">Phone number</label>
<input type="tel" id="phone" name="phone" autocomplete="tel"
       placeholder="e.g. 024 123 4567">

A bonus: clicking the label now puts the cursor in the box, which gives phone users a bigger area to tap. A placeholder is still fine for an example, as long as it isn't the only label.

4. Use real buttons, not clickable divs

A <div> with a click handler looks like a button to a mouse user, but keyboard users can't reach it with Tab, and screen readers don't announce it as a button. A real <button> gets all of that for free (WCAG 2.1.1 and 4.1.2):

<!-- Before -->
<div class="btn" onclick="addToCart()">Add to cart</div>

<!-- After -->
<button type="button" class="btn" onclick="addToCart()">Add to cart</button>

The rule of thumb: links go places, buttons do things. If it opens another page, use <a href>. If it does something on this page, use <button>. You can style either one to look however you like with CSS.

5. Put headings in order

Screen reader users often jump from heading to heading to get a feel for a page, the way you skim a newspaper. That only works if the headings are real heading tags, not big bold paragraphs, and if they're in a sensible order (WCAG 1.3.1):

<h1>Mama Esi's Chop Bar</h1>
  <h2>Today's menu</h2>
    <h3>Soups</h3>
    <h3>Rice dishes</h3>
  <h2>Opening hours</h2>

Use one <h1> for the page's main topic and don't skip levels, such as jumping from <h2> to <h4> because you liked the size. Pick headings for their meaning, and set their size with CSS.

6. Write link text that makes sense on its own

Screen readers can list every link on a page. A list that says "click here, click here, read more" tells the listener nothing. WCAG 2.4.4 asks that a link's purpose be clear from its text, or from the sentence around it. Text that makes sense on its own is even better:

<!-- Before -->
<p>To see our delivery prices, <a href="/delivery">click here</a>.</p>

<!-- After -->
<p>See our <a href="/delivery">delivery prices for Accra and Kumasi</a>.</p>

This helps everyone who skims, and search engines use link text to understand pages too.

7. Check your colour contrast

Pale grey text on white looks stylish on a big laptop screen and vanishes on a phone in the sun. WCAG sets clear minimums for the contrast ratio between text and its background (WCAG 1.4.3, AA):

  • At least 4.5:1 for normal text.
  • At least 3:1 for large text: 24 CSS pixels and up, or about 18.66 pixels if it's bold.
  • At least 3:1 for the parts of controls you need to see, like a text box's border or a focus ring (WCAG 1.4.11).

The ratio comes from a formula you can run yourself. This Python version follows WCAG's definition of relative luminance:

def luminance(hex_colour):
    """Relative luminance of a colour like "#767676", as WCAG defines it."""
    hex_colour = hex_colour.lstrip("#")
    channels = []
    for i in (0, 2, 4):
        c = int(hex_colour[i:i + 2], 16) / 255
        channels.append(c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4)
    r, g, b = channels
    return 0.2126 * r + 0.7152 * g + 0.0722 * b


def contrast(text, background):
    lighter, darker = sorted([luminance(text), luminance(background)], reverse=True)
    return (lighter + 0.05) / (darker + 0.05)


for colour in ["#aaaaaa", "#767676", "#1b3a6a"]:
    print(f"{colour} on white: {contrast(colour, '#ffffff'):.2f}:1")
#aaaaaa on white: 2.32:1
#767676 on white: 4.54:1
#1b3a6a on white: 11.29:1

The light grey #aaaaaa fails; #767676 is about the lightest grey that passes on white. Don't round up: 4.49:1 is a fail. You don't need to code it every time, though: the colour picker in Chrome's DevTools shows the ratio for any text you inspect.

8. Don't rely on colour alone

Some people can't tell red from green, and on a dim screen colours blur together. If colour is the only way you show something, add text or an icon too (WCAG 1.4.1):

<!-- Before: only the red border says something is wrong -->
<input type="text" id="momo" class="error">

<!-- After: the error is in words, and tied to the field -->
<label for="momo">Mobile money number</label>
<input type="tel" id="momo" class="error" aria-describedby="momo-error">
<p id="momo-error">Enter a 10-digit number, like 024 123 4567.</p>

aria-describedby makes screen readers read the error message when the field gets focus. The same idea applies to charts (add labels), links (underline them in body text) and "required" fields (write "required", don't just colour the label).

9. Keep the focus outline visible

When you press Tab, browsers draw an outline around the focused link or button. Many sites remove it with outline: none because it "looks ugly", and keyboard users are left lost (WCAG 2.4.7, AA). Instead of removing it, design a clear one. :focus-visible shows it for keyboard users, without drawing it on every mouse click:

/* Never do this on its own */
button:focus {
  outline: none;
}

/* Do this instead */
a:focus-visible,
button:focus-visible {
  outline: 3px solid #1b3a6a;
  outline-offset: 2px;
}

/* Stop a sticky header from covering focused links */
html {
  scroll-padding-top: 80px;
}

That last rule is for a WCAG 2.2 criterion, 2.4.11 Focus Not Obscured (AA): the focused item mustn't be completely hidden behind sticky headers, cookie banners or chat buttons. Set the number to your header's height.

10. Make tap targets big enough

Tiny icons are hard to hit for people with shaky hands, large fingers, or a phone bouncing on a rough road. WCAG 2.2 added 2.5.8 Target Size (Minimum) (AA): buttons and links must be at least 24 by 24 CSS pixels, or have enough space around them that they don't crowd each other. Links inside a sentence are an exception.

.icon-button {
  min-width: 44px;
  min-height: 44px;
}

24 pixels is the minimum. For buttons people tap often, like "Add to cart" or a menu icon, many design guides suggest about 44 to 48 pixels, and WCAG's stricter AAA rule (2.5.5) asks for 44.

Test your page in five minutes

You don't need special equipment to find the worst problems:

  1. Put the mouse away. Press Tab through the whole page. Can you see where you are, reach every link and button, and use them with Enter or Space?
  2. Zoom to 200% with Ctrl and +. Does the text still fit, without overlapping or cutting off?
  3. Run Lighthouse in Chrome's DevTools, or the free axe browser extension, and fix what they report.

Automated tools are a great start, but they can't catch everything. They can tell that an image has alt text, not whether the text makes sense. That's why the keyboard check matters.

Learn accessibility on JeliScript

These ten fixes are a strong start. The Web Accessibility course goes much further: how people use screen readers, keyboards and zoom, how to read WCAG 2.2, accessible forms and error messages, skip links, the contrast formula step by step, ARIA for menus, dialogs and tabs, and testing with the accessibility tree, Lighthouse and axe.

Accessibility starts with good HTML and CSS. If you're new to them, begin with the HTML Crash Course and the CSS Crash Course, which both run right in your browser.

Comments

Log in to join the conversation.

Loading comments...