BiTree
  • Search For Lessons
  • Curriculum
  • Pricing
  • For Educators
  • Become a Tutor
  • About
  • Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
BiTree

Live coding lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Search For Lessons
  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Become a Tutor
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 BiTree. All rights reserved.
Curriculum/Web Development/Semantic HTML, Accessibility, and WCAG
40 minBeginner

Semantic HTML, Accessibility, and WCAG

After this lesson, you will be able to: Build accessible webpages using semantic HTML, proper form labels, ARIA roles where appropriate, keyboard-friendly focus management, and WCAG AA color contrast — and explain why accessibility is a legal and professional requirement, not a nice-to-have.

Most web developers learn HTML and never learn accessibility properly, then ship pages that break for users with screen readers, keyboard-only navigation, or low vision. In 2025 that is no longer acceptable. The Americans with Disabilities Act has been the basis for thousands of US web accessibility lawsuits in the last decade, and the European Accessibility Act took effect in June 2025 with real fines attached. Beyond the legal angle, accessibility is also a hiring filter: a junior frontend candidate who can talk about semantic HTML, ARIA, and WCAG signals professional craft. This lesson takes you from zero to fluent on each of those.

Prerequisites:HTML Fundamentals

Why accessibility matters professionally

Three reasons that override personal opinion on the subject. First, the law. The Americans with Disabilities Act (ADA) has been the basis for major web accessibility settlements at Target, Domino's, and Netflix; the European Accessibility Act took effect 28 June 2025 with serious enforcement penalties for consumer-facing sites and apps; US federal agencies are bound by Section 508. Second, the audience. Roughly 15% of the global population lives with some form of disability. A page that breaks for screen readers is a page that excludes a sixth of your potential users. Third, the job market. Every team you'll interview at considers accessibility a senior-engineer-level concern, and a junior candidate who can talk about it credibly stands out. That alone makes this lesson worth your time.

Semantic HTML — the foundation

Most accessibility wins do not require ARIA or special attributes. They come from picking the right HTML tag. Use `<header>` for the top of the page, `<nav>` for the main navigation, `<main>` for the primary content (one per page), `<article>` for self-contained content like a blog post, `<section>` for thematic groupings inside that, `<aside>` for sidebars, and `<footer>` for the bottom. Screen readers use these landmarks to let users jump straight to navigation, main content, or footer with a keystroke. A page built entirely from `<div>` is a wall of text for a screen reader user. A page built from semantic tags is navigable from the first try.

Non-semantic vs semantic, side by side

The non-semantic version below renders identically to the semantic one in a sighted browser. To a screen reader, the second one is a navigable document; the first one is a single block.

html
<!-- Bad. Everything is a div. Screen reader sees one big block. -->
<div class="top">
<div class="links">
<div onclick="goHome()">Home</div>
<div onclick="goAbout()">About</div>
</div>
</div>
<div class="page">
<div class="post">
<div class="title">My Post</div>
<div>Post body...</div>
</div>
</div>
<!-- Good. Semantic landmarks, real buttons, real headings. -->
<header>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<article>
<h1>My Post</h1>
<p>Post body...</p>
</article>
</main>

Forms, labels, and error messages

Every form input must be associated with a `<label>`. The cleanest pattern is `<label for="id">…</label>` paired with `<input id="id">`. A label that just sits next to an input visually is invisible to a screen reader — the explicit `for` / `id` link is what makes it announceable. Group related fields with `<fieldset>` and `<legend>` (think: radio button group, billing address block). For inline error messages, link the error text to the input with `aria-describedby`, and use `aria-invalid="true"` on the input itself when there's a validation error so screen readers announce the failure. Never communicate state with color alone — a red border without text reads as 'normal input' to a screen reader.

Accessible form pattern

Pattern you can copy. Notice the label/input ID pairing, the `aria-describedby` linking the error message back to the input, and the use of a real `<button>` instead of a `<div onclick>`.

html
<form>
<label for="email">Email address</label>
<input
id="email"
name="email"
type="email"
required
aria-describedby="email-error"
aria-invalid="true"
/>
<p id="email-error" role="alert">
Enter a valid email like [email protected].
</p>
<fieldset>
<legend>Preferred contact method</legend>
<label><input type="radio" name="contact" value="email" /> Email</label>
<label><input type="radio" name="contact" value="phone" /> Phone</label>
</fieldset>
<button type="submit">Sign up</button>
</form>

💡 The first rule of ARIA: do not use ARIA

ARIA roles and attributes (`role="button"`, `aria-label`, `aria-hidden`, etc.) exist for cases native HTML cannot cover. They are not a substitute for using the right tag. A `<div role="button" tabindex="0" onclick=…>` is strictly worse than a `<button>` — it still needs keyboard handlers and focus styles you would have gotten for free. Reach for ARIA only after you've confirmed no native element fits.

Keyboard navigation and focus

Roughly 8% of users browse without a mouse — power users, motor-impaired users, screen reader users. They all rely on the Tab key to walk through your interactive elements. Two rules. First, Tab order must match visual order. If a user tabs and the focus jumps from the header straight to the footer, you've broken the page. Second, every focusable element needs a visible focus ring. Browsers give you one for free; lots of CSS resets remove it (`*:focus { outline: none; }`) — never do that. Either keep the default outline or replace it with something equally visible.

Color contrast and WCAG AA

WCAG 2.1 Level AA is the standard most laws point at. The contrast rule: normal text needs a contrast ratio of at least 4.5:1 against its background; large text (18pt+ or 14pt bold+) needs at least 3:1. Pure black on white is 21:1; light gray on white is often under 4:1 and fails. You don't measure this by eye. Tools do it for you — DevTools' Color picker shows the ratio inline, and design tools like Figma have plugins that check every text layer. If you're picking a brand color, test it against your background before you commit.

Tools that catch accessibility bugs for you

Three free tools cover most of what a manual audit would find. **Lighthouse** is built into Chrome DevTools (open DevTools → Lighthouse → Accessibility). It runs in 30 seconds and surfaces missing labels, low contrast, missing alt text, and tab-order issues. **axe DevTools** is a browser extension from Deque (the company that wrote the most-used accessibility testing library). More thorough than Lighthouse on edge cases. **A screen reader** — NVDA is free on Windows, VoiceOver ships with macOS (Cmd+F5). Spend ten minutes navigating one of your own pages with the screen reader and your eyes closed. It is the single most useful exercise on this list.

Refactor an inaccessible form

The starter code is a form that mostly works for a sighted mouse user and is broken for everyone else. Refactor it to: real `<button>` instead of `<div onclick>`; `<label for="…">` paired with `<input id="…">` on both inputs; `<fieldset>` + `<legend>` around the radio group. Pass once your code contains the four required patterns below.

Loading exercise…
Quick Check

Which of these snippets has the most serious accessibility problem?

Read each line and pick the worst offender.

💡 Common mistakes only experienced devs catch

Five things even good juniors miss. (1) Using `aria-label` on every element 'to be safe' — overrides the visible label and makes the page louder, not clearer. (2) `aria-hidden="true"` on a focusable element — the screen reader skips it but the keyboard can still tab into it, which is the worst of both worlds. (3) Click handlers on `<span>` or `<div>` with `cursor: pointer` and no keyboard handler — looks clickable, isn't reachable by Tab. (4) Skipping heading levels (h1 → h3 with no h2) — confuses screen-reader outline navigation. (5) Using color alone for form errors (red border, no text) — invisible to color-blind users. Always pair color with text and an icon.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←HTML Fundamentals
Back to Web Development
CSS Fundamentals→