Accessibility · Frontend · HTML · Test automation
Web Accessibility (WCAG) Basics: A Practical Guide for Developers
WCAG 2.2 from a developer's point of view: semantic HTML, keyboard access, focus management, colour contrast, using ARIA correctly and automated accessibility tests.

In most projects accessibility sits on the "we'll get to it" list. Yet a site that works for a screen-reader user also reads better for search engines and AI agents; keeping the Lighthouse accessibility score at 100 on this site directly helped SEO too. Here are the basics every developer should know.
1. Semantic HTML first
A button made of a div and onClick doesn't take keyboard focus, isn't announced as a button and doesn't respond to Enter or Space.
<!-- Wrong -->
<div class="btn" onclick="save()">Save</div>
<!-- Right -->
<button type="button" onclick="save()">Save</button>
Use header, nav, main, article and footer for page structure. Have one h1 per page and don't skip heading levels.
2. Everything must work with a keyboard
Do a mouse-free pass: tab through the page and check:
- Does focus order match visual order?
- Is the focused element visible? Writing
outline: nonewith no replacement is the most common mistake. - When a modal opens, does focus move into it, and return to the trigger when it closes?
:focus-visible { outline: 3px solid #4f8cff; outline-offset: 2px; }
3. Colour contrast
WCAG AA requires at least 4.5:1 contrast for normal text and 3:1 for large text. Grey on light grey looks elegant and many users can't read it. Don't convey information by colour alone either; instead of "red fields are invalid", add an icon and text.
4. Forms
<label for="email">Email</label>
<input id="email" type="email" autocomplete="email" aria-describedby="email-hint" />
<p id="email-hint">Use your work email.</p>
A placeholder is not a label. Link error messages to the field with aria-describedby and set aria-invalid="true".
5. ARIA: little and correct
The first rule of ARIA: if a native HTML element does the job, don't use ARIA. Wrong ARIA is worse than none. A few useful ones:
aria-label: for icon-only buttons.aria-expanded: for dropdown and accordion state.aria-live="polite": to announce notifications and loading states.
6. Images and media
Give meaningful images alt text describing what they show and decorative ones alt="". Provide captions for video and honour prefers-reduced-motion for animation. The avatar animation on this blog stops entirely for users who prefer reduced motion.
7. Automated tests, but not alone
Add accessibility checks to CI with axe-core, Lighthouse and Playwright:
import AxeBuilder from '@axe-core/playwright';
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
Automated tools catch roughly a third of issues. For the rest you need a short manual pass with the keyboard and a screen reader (VoiceOver, NVDA).
Conclusion
Semantic HTML, visible focus, enough contrast, labelled forms and sparing ARIA: these five habits fix most accessibility problems. I cover the CI side in frontend CI with GitHub Actions and web E2E tools in Playwright vs Cypress vs Selenium.


