Sub topic 13
Checking Accessibility
A newsroom page serves journalists on deadline, and some of them use screen readers, keyboard navigation, magnification, or captions. This chapter shows how to check that the page works for them. You will combine automated scans with a short manual routine, and you will fix the errors that press pages tend to have.
Prerequisites and scope
This chapter assumes you have read the earlier chapters on semantic HTML and on preparing logos, photos, and downloads. You should be comfortable reading HTML and CSS and running a command in a terminal. The target is WCAG 2.2 level AA, the standard most legal requirements and procurement checklists refer to. WCAG is the Web Content Accessibility Guidelines, published by the W3C.
The working model
WCAG groups its requirements under four principles, often shortened to POUR:
- Perceivable: content can be seen or heard in some form, for example through text alternatives for images and enough color contrast.
- Operable: every control works with a keyboard, focus is visible, and targets are not tiny.
- Understandable: the language is declared, labels are clear, and behavior is predictable.
- Robust: the markup is valid enough for assistive technology to interpret it. Semantic elements are the main tool here.
Automated tools can detect only some problems. They can tell that an image has no alt attribute. They cannot tell whether the alt text is useful. So the routine has three layers: automated scan, keyboard pass, and screen reader spot check.
Structure and landmarks
The page from the semantic HTML chapter already has a main element, section elements, and a heading hierarchy. Check these points:
- Exactly one
h1per page, and no skipped levels such ash2followed byh4. - Each
sectionhas an accessible name.aria-labelledbypointing at its heading does this. - The
htmlelement declares a language, such as<html lang="en">. Without it, screen readers may pronounce English text with the wrong voice. - A skip link lets keyboard users jump past the header navigation.
<body>
<a class="skip-link" href="#newsroom">Skip to newsroom content</a>
<header><nav aria-label="Primary">...</nav></header>
<main id="newsroom" tabindex="-1">...</main>
</body>The skip link should stay hidden until it receives focus, and then it must become visible:
.skip-link {
position: absolute;
left: -9999px;
}
.skip-link:focus {
left: 1rem;
top: 1rem;
padding: 0.5rem 1rem;
background: #fff;
color: #000;
outline: 3px solid #1a56db;
}The tabindex="-1" on main lets the browser move focus there when the link is activated. Some older browsers otherwise scroll without moving focus.
Links, images, and downloads
Press kits contain many repeated links, which causes most of the problems on these pages. Screen reader users often pull up a list of all links on a page. A list that reads "Download, Download, Download, Read more" is useless.
Bad and better versions:
<!-- Bad -->
<a href="/assets/acme-logo.zip">Download</a>
<!-- Better -->
<a href="/assets/acme-logo.zip">Download Acme logo pack (ZIP, 2.4 MB)</a>Including the file type and size also helps every user decide before clicking.
For images, apply these rules:
- A photo that carries meaning needs
alttext describing what it shows, such as "Jordan Lee, CEO of Acme, at the Widget 2 launch". - A purely decorative image gets
alt="", an empty value, so screen readers skip it. Omitting the attribute entirely is different and is an error, because some readers then announce the file name. - A logo preview in the asset gallery needs
alttext naming the asset and the variant, for example "Acme logo, full color on white". Journalists need to tell the variants apart. - Do not put the only copy of important text, such as a quote, inside an image.
Downloadable PDFs are part of the page experience. Export fact sheets and bios from the source document with tags enabled, set the document language and title, and give images alt text before export. Also offer the same content as HTML, which is more reliable for assistive technology.
Keep the time element with its datetime value. It gives machines a reliable date, while the visible text stays human-readable.
Color, focus, zoom, and target size
Check these with your eyes and a few browser settings.
| Check | WCAG 2.2 AA requirement | How to test |
|---|---|---|
| Text contrast | 4.5:1 for normal text, 3:1 for large text (about 24 px, or 19 px bold) | Browser DevTools color picker, or a contrast checker |
| Non-text contrast | 3:1 for input borders, focus rings, and meaningful icons | Same tools |
| Focus visible | A visible indicator on every focused control | Press Tab through the page |
| Reflow | No horizontal scrolling at 320 CSS pixels wide (400% zoom on a 1280 px window) | Zoom the browser to 400% |
| Text spacing | No lost content when line height and spacing are increased | Apply a text-spacing bookmarklet or user stylesheet |
| Target size | At least 24 by 24 CSS pixels for pointer targets, with some exceptions | Inspect element sizes |
| Color alone | Meaning is never carried by color only | View the page in grayscale |
Never remove the focus outline with outline: none unless you replace it with something equally visible. Brand colors are a common contrast failure. A light gray tagline on white, or white text on a pastel brand color, often falls below 4.5:1. Check the actual hex values from your brand guidelines before the page ships.
The keyboard pass
Put the mouse aside and use only the keyboard.
- Load the page and press Tab once. The skip link should appear.
- Keep pressing Tab. Focus should move in a logical order that matches the visual order, and you should always see where it is.
- Press Enter on each link and button. Everything clickable must be reachable and activatable.
- Open any menu, gallery, or lightbox. Check that Escape closes it and that focus returns to the control that opened it.
- Make sure you never get trapped. Shift+Tab must always let you go back.
Failures here usually come from div or span elements given click handlers instead of using real a or button elements. Using native elements gives you keyboard support and the right role for free.
Screen reader spot check
You do not need to be an expert. Use NVDA on Windows (free), VoiceOver on macOS, or TalkBack on Android. Check four things:
- Open the headings list. Does it read like an outline of the page?
- Open the landmarks list. Do you hear "main", "navigation", and named regions such as "Press releases"?
- Open the links list. Is each link understandable out of context?
- Move through the media contact block. Is the email address announced as a link?
Automated checks
Run at least one automated tool on every page template, and rerun it after each design change. Common choices are axe DevTools (browser extension), Lighthouse (built into Chrome), and the command-line tool pa11y.
You can also add a small check of your own to a build step. This Python script uses only the standard library. It flags missing alt attributes, vague link text, skipped heading levels, and a wrong number of h1 elements:
import re
import sys
from html.parser import HTMLParser
VAGUE = {"click here", "here", "download", "read more", "more", "link"}
class Checker(HTMLParser):
def __init__(self):
super().__init__()
self.problems = []
self.h1_count = 0
self.last_level = 0
self.in_link = False
self.link_text = []
self.link_line = 0
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
line = self.getpos()[0]
if tag == "img" and "alt" not in attrs:
self.problems.append(f"line {line}: img has no alt attribute")
if re.fullmatch(r"h[1-6]", tag):
level = int(tag[1])
if level == 1:
self.h1_count += 1
if self.last_level and level > self.last_level + 1:
self.problems.append(
f"line {line}: heading jumps from h{self.last_level} to h{level}"
)
self.last_level = level
if tag == "a":
self.in_link = True
self.link_text = []
self.link_line = line
def handle_data(self, data):
if self.in_link:
self.link_text.append(data)
def handle_endtag(self, tag):
if tag == "a" and self.in_link:
text = " ".join("".join(self.link_text).split()).lower()
if text in VAGUE:
self.problems.append(
f"line {self.link_line}: vague link text '{text}'"
)
self.in_link = False
def main(path):
checker = Checker()
with open(path, encoding="utf-8") as f:
checker.feed(f.read())
if checker.h1_count != 1:
checker.problems.append(f"expected 1 h1, found {checker.h1_count}")
for problem in checker.problems:
print(problem)
return 1 if checker.problems else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1]))Run it with python check_a11y.py newsroom.html. A non-zero exit code makes it usable in a continuous integration job. It is a supplement to a real scanner and not a replacement for one.
Common errors on newsroom pages
| Error | Why it happens | Fix |
|---|---|---|
| Many links named "Download" | Template repeats a button label | Include the asset name, type, and size in the link text |
| Logo gallery with empty or missing alt | Images treated as decoration | Describe each variant, for example "Acme logo, white on dark" |
| Headings chosen for size | `h4` used because it looks smaller | Pick the heading level for structure, then style with CSS |
| Contrast failure on brand colors | Palette taken straight from brand guide | Test each foreground and background pair |
| Untagged PDF fact sheet | Exported as a print file | Export with tags, and also publish an HTML version |
| Email shown as an image | Spam-avoidance attempt | Use a real `mailto:` link as in the earlier markup |
| Focus outline removed | Designer preference | Restore a visible custom focus style |
Exercises
Exercise
A press kit page has six links that all read "Download", each next to a different file. Explain why this is a problem and rewrite two of the links so they pass.
Show answer
Screen reader users often navigate by listing all links on the page, and a list of six identical "Download" entries gives no way to tell the files apart. Each link's text must make sense out of context. Examples: "Download Acme logo pack (ZIP, 2.4 MB)" and "Download Widget 2 fact sheet (PDF, 310 KB)". Including file type and size also helps sighted users.
Exercise
Your script reports "line 42: heading jumps from h2 to h4". The h4 is in the "Media contact" section and was chosen because it looks smaller. What is the correct fix, and what should you do for the visual size?
Show answer
Change the element to h3 so the levels do not skip, because heading levels express structure and not appearance. Control the visual size with CSS, such as a class that sets the font size on the h3.
Exercise
Name the three layers of checking in this chapter and one thing each layer catches that the others are likely to miss.
Show answer
The automated scan catches mechanical errors such as missing alt attributes or low contrast ratios across the whole page. The keyboard pass catches focus order problems, missing focus indicators, and keyboard traps. The screen reader spot check catches unclear alt text, vague link text, and poorly named landmarks.