---
title: "Web Accessibility (WCAG) Basics: A Practical Guide for Developers"
description: "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."
url: https://sanderyaz.com/en/blog/web-accessibility-basics/
author: Sander Yazıcıoğlu
date: 2026-12-02
updated: 2026-12-02
lang: en
tags: ["Accessibility","Frontend","HTML","Test automation"]
---

# Web Accessibility (WCAG) Basics: A Practical Guide for Developers

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.

```html
<!-- 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: none` with no replacement is the most common mistake.
- When a modal opens, does focus move into it, and return to the trigger when it closes?

```css
: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

```html
<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:

```ts
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](/en/blog/github-actions-frontend-ci/) and web E2E tools in [Playwright vs Cypress vs Selenium](/en/blog/playwright-vs-cypress-vs-selenium/).

---

About the author: [Sander Yazıcıoğlu](https://sanderyaz.com/en/about/). Sander Yazıcıoğlu is a Senior Full-Stack Developer in Istanbul. At LiveTesting he builds the backend, frontend, realtime systems and Appium automation of a real-device testing platform; before that he built enterprise Angular apps at Testinium and Loadium.
