Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Lab · 30 min · revision 2

Lab: Mark Up an Article Page and Inspect Its Accessibility Tree

Convert a div-only news article into semantic HTML, validate it, run structural checks against its DOM, and confirm the result in the browser accessibility tree.

Contentsand lesson path

What you will learn

  • Structure a page with a correct document skeleton, metadata, a logical heading hierarchy and landmark elements (header, nav, main, footer).
  • Choose the semantic element for each piece of content (links vs buttons, lists, data tables with headers, figures, dialog, details) instead of generic div and span.
  • Provide text alternatives and labels: meaningful alt text, captions for media, and a programmatic label for every form control.
  • Validate markup and inspect the accessibility tree in browser DevTools to confirm the intended structure is exposed.

01. Goal and setup

By the end of this lab you will have taken a page that is one flat pile of div elements and turned it into semantic HTML: correct document skeleton, landmarks, a heading outline without gaps, alt text on images, and a label on every control. You will prove the result three ways — a validator exit code, a DOM check script, and the accessibility tree in your browser's DevTools. This is the same conversion the skill's practice task asks for, so keep your finished files.

You need: Node.js with npm, and any current browser. jsdom 31 needs Node 22.22.2 or later on the 22 line (or 24.15 and later); check with node --version. Everything installs locally into the lab folder; nothing goes global. The install line pins the versions this lab was last run with: html-validate 11.22.1 and jsdom 31.0.1. The lab folder layout:

Project layout
lighthouse-log/
├── .htmlvalidate.json     validator config (step 1)
├── div-article.html       the provided starting page
├── article.html           your semantic rewrite
├── checks.js              DOM check script (step 6)
└── node_modules/          local dependencies, never committed

02. Step 1: set up the folder and meet the starting page

Terminal
mkdir lighthouse-log && cd lighthouse-log
npm init -y
npm install [email protected] [email protected]
npx html-validate --version
Expected output (last command)
html-validate-11.22.1

Create the starting page exactly as given — a plausible article page where every box is a div and a class carries all the meaning:

HTML · div-article.html, the provided starting point
<!DOCTYPE html>
<html>
  <head>
    <title>The Lighthouse Keeper's Log</title>
  </head>
  <body>
    <div class="site-head">
      <div class="site-name">The Lighthouse Keeper's Log</div>
      <div class="menu">
        <a href="/news.html">News</a>
        <a href="/tides.html">Tides</a>
        <a href="/archive.html">Archive</a>
      </div>
    </div>
    <div class="page">
      <div class="headline">LED lamps arrive at Point Fang</div>
      <div class="subhead">Brighter nights, lower bills</div>
      <div class="article-body">
        <p>The new lamps reached the tower on Thursday, two weeks
        behind schedule. The crane could not operate in the morning
        fog.</p>
        <img src="lamp-crane.jpg">
        <p>The light will be tested for one week before the old lamps
        are removed. Neighbours may notice a different flash
        pattern.</p>
      </div>
      <div class="related">
        <div class="related-title">More from the archive</div>
        <p><a href="/2019/storm-damage.html">Storm damage in 2019</a></p>
      </div>
      <div class="subscribe">
        <p>Get the log by email</p>
        <input id="subscribe-email" type="email">
        <button></button>
      </div>
    </div>
    <div class="site-foot">© 2026 The Lighthouse Keeper's Log</div>
  </body>
</html>

Then give the validator a config that extends its recommended preset with one extra rule. As the previous lesson noted, label checks are off by default:

JSON · .htmlvalidate.json
{
  "extends": ["html-validate:recommended"],
  "rules": { "input-missing-label": "error" }
}
Terminal · validate the starting page
npx html-validate --formatter text div-article.html
echo "exit code: $?"
Expected output · five errors (file path trimmed per line)
2:2: error [element-required-attributes] <html> is missing required "lang" attribute
22:10: error [wcag/h37] <img> is missing required "alt" attribute
33:10: error [input-missing-label] <input> element does not have a <label>
34:10: error [no-implicit-button-type] <button> is missing recommended "type" attribute
34:10: error [text-content] <button> must have accessible text
exit code: 1

Five errors before you have written a line of CSS. Note what the validator did not complain about: every one of those div elements. Markup can be valid and still say nothing — the div-only page is bad HTML not because it breaks rules, but because it hides them. Keep this output; it is your before picture.

03. Step 2: fix the skeleton and mark the landmarks

Copy div-article.html to article.html and rebuild it there, top to bottom. First the head — add the language, the encoding and the viewport, and write a title that names the article as well as the site — then the landmarks around the content:

HTML · article.html — head and skeleton
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>LED lamps arrive at Point Fang — The Lighthouse Keeper's Log</title>
    <meta name="description"
      content="New lamps reach the Point Fang lighthouse; what changes for neighbours.">
  </head>
  <body>
    <header>
      <p>The Lighthouse Keeper's Log</p>
      <nav aria-label="Site sections">
        <ul>
          <li><a href="/news.html">News</a></li>
          <li><a href="/tides.html">Tides</a></li>
          <li><a href="/archive.html">Archive</a></li>
        </ul>
      </nav>
    </header>
    <main>
      <!-- the article, aside and subscribe form follow -->
    </main>
    <footer>
      <p>© 2026 The Lighthouse Keeper's Log</p>
    </footer>
  </body>
</html>

The menu stops being a div of loose links and becomes a list inside nav, labelled so it can be told apart from any other navigation. The site name drops its heading ambitions and the copyright leaves the page div entirely: both are repeated chrome, not this page's content, so they sit outside main.

04. Step 3: build the article and its heading outline

Inside main, the story becomes an article with an h1, the standfirst becomes a plain paragraph, and the photo gets wrapped in a figure with alt text and a caption:

HTML · article.html — the article inside main
<article>
  <h1>LED lamps arrive at Point Fang</h1>
  <p class="standfirst">Brighter nights, lower bills</p>
  <p>The new lamps reached the tower on Thursday, two weeks behind
  schedule. The crane could not operate in the morning fog.</p>
  <figure>
    <img src="lamp-crane.jpg"
      alt="A crane lifting a lamp crate towards the lighthouse lamp room"
      width="800" height="533">
    <figcaption>The crane at work on Thursday morning.</figcaption>
  </figure>
  <p>The light will be tested for one week before the old lamps are
  removed. Neighbours may notice a different flash pattern.</p>
</article>
<aside>
  <h2>More from the archive</h2>
  <ul>
    <li><a href="/2019/storm-damage.html">Storm damage in 2019</a></li>
  </ul>
</aside>

The alt text describes what the picture shows at the point where it appears; the caption adds when it was taken. One h1, then the aside's h2 — no gaps in the outline.

05. Step 4: give every control a name

HTML · article.html — the subscribe form
<section aria-labelledby="subscribe-heading">
  <h2 id="subscribe-heading">Get the log by email</h2>
  <form action="/subscribe" method="post">
    <label for="subscribe-email">Email address</label>
    <input id="subscribe-email" name="email" type="email"
      autocomplete="email" required>
    <button type="submit">Subscribe</button>
  </form>
</section>

Three fixes in nine lines. The heading is reused as the section's accessible name through aria-labelledby, so the region is announced as "Get the log by email" instead of an anonymous block. The input gains an explicit label joined by for and id, plus autocomplete so browsers can fill it. The empty button gets an explicit type and visible text — it can finally be announced and pressed.

06. Step 5: validate again

Terminal · validate the rewrite
npx html-validate --formatter text article.html
echo "exit code: $?"
Expected output
exit code: 0

No error lines and exit code 0: every rule, including the label check you switched on, now passes. An empty validator report is the floor, not the ceiling — it says the markup follows the rules, not that the choices are right. That is what the next two steps are for.

07. Step 6: check the structure from the DOM

The validator checks rules; this script checks your intentions — one h1, no skipped heading levels, landmarks present, a name on every image and control. It parses the file with jsdom, a JavaScript implementation that approximates the browser DOM, so it runs with no browser open:

JavaScript · checks.js
// Structural checks for the lab page. Run: node checks.js article.html
const { JSDOM } = require('jsdom');
const { readFileSync } = require('node:fs');
const dom = new JSDOM(readFileSync(process.argv[2], 'utf8'));
const { document } = dom.window;
let failures = 0;
const check = (ok, label) => {
  console.log(`${ok ? 'PASS' : 'FAIL'}  ${label}`);
  if (!ok) failures += 1;
};

check(document.doctype?.name === 'html', 'doctype is html');
check(document.documentElement.lang !== '', 'html has a lang attribute');
const headings = [...document.querySelectorAll('h1, h2, h3, h4, h5, h6')];
check(document.querySelectorAll('h1').length === 1, 'exactly one h1');
let previous = 0;
for (const heading of headings) {
  const level = Number(heading.tagName.slice(1));
  const text = heading.textContent.trim();
  check(level <= previous + 1, `no skipped level before h${level}: ${text}`);
  previous = level;
}
for (const tag of ['header', 'nav', 'main', 'footer']) {
  check(document.querySelector(tag) !== null, `landmark <${tag}> present`);
}
for (const img of document.querySelectorAll('img')) {
  check(img.hasAttribute('alt'), `img has alt: ${img.getAttribute('src')}`);
}
for (const control of document.querySelectorAll('input, textarea, select')) {
  const labelled =
    (control.id && document.querySelector(`label[for="${control.id}"]`)) ||
    control.closest('label');
  check(labelled !== null, `<${control.tagName.toLowerCase()}> has a label`);
}
for (const button of document.querySelectorAll('button')) {
  check(button.textContent.trim() !== '', 'button has visible text');
}
process.exit(failures === 0 ? 0 : 1);
Terminal
node checks.js article.html
echo "exit code: $?"
Expected output
PASS  doctype is html
PASS  html has a lang attribute
PASS  exactly one h1
PASS  no skipped level before h1: LED lamps arrive at Point Fang
PASS  no skipped level before h2: More from the archive
PASS  no skipped level before h2: Get the log by email
PASS  landmark <header> present
PASS  landmark <nav> present
PASS  landmark <main> present
PASS  landmark <footer> present
PASS  img has alt: lamp-crane.jpg
PASS  <input> has a label
PASS  button has visible text
exit code: 0

Point the same script at the starting page — node checks.js div-article.html — and nine checks fail. That contrast is the lab in one screen: same words, same visible design, different structure.

08. Step 7: read the accessibility tree

Everything so far has been inference. The accessibility tree is the ground truth: the reduced copy of the DOM that assistive technology actually receives, with each element's role and name. Open article.html in Chrome, press F12, go to the Elements panel and open the Accessibility pane (in Firefox, use the Accessibility Inspector). Walk the tree and find these entries — here trimmed from an automated snapshot of the finished page:

Accessibility tree · finished page (trimmed snapshot)
- banner:
  - paragraph: The Lighthouse Keeper's Log
  - navigation "Site sections":
    - link "News"    ·    link "Tides"    ·    link "Archive"
- main:
  - article:
    - heading "LED lamps arrive at Point Fang" [level=1]
    - figure "The crane at work on Thursday morning.":
      - img "A crane lifting a lamp crate towards the lighthouse lamp room"
  - complementary:
    - heading "More from the archive" [level=2]
  - region "Get the log by email":
    - textbox "Email address"
    - button "Subscribe"
- contentinfo:

Match each line to the markup that earned it: header became banner, the labelled nav became navigation "Site sections", aside became complementary, the footer became contentinfo, and the form controls carry the names you gave them. Then try the honest experiment on the div-only page: the same pane shows a flat run of generic nodes and text, with no landmarks and no headings, and the image, the text box and the button keep their roles but have no names — everything a screen-reader user would have lost.

One habit to take away: when anything you build is announced oddly, look in this pane before guessing. The tree shows what software receives; your markup is only a way of writing it down.

09. If something goes wrong

10. Check your understanding

Practice check · 3 questions

Reading the lab tools

Three judgements about the checks you just ran.

Q1. In Step 1, `.htmlvalidate.json` explicitly added `"input-missing-label": "error"`. What would happen if that rule were omitted?
Q2. Your own `checks.js` prints FAIL for "exactly one h1" while the validator passes. What is going on?
Q3. In the DevTools accessibility pane, the archive links sit under a node announced as `complementary`. Which element in your markup produced that role?
Practice only: not graded, not saved, not evidence.

11. Apply it

Extend the page, as the skill's practice task suggests beyond the basics: add a tide table for the week — a table with a caption, th scope="col" for the days and th scope="row" for high and low water — and a details element answering "Why did the flash pattern change?". Rerun the validator and checks.js (they should stay clean, though the script does not yet know about tables — extend it with a check that every table has a caption), then confirm the new elements in the accessibility pane. For what comes next in the roadmap, see /skills/css-fundamentals and /skills/web-accessibility.

12. Review prompt

Without looking back: list the five validator errors the div-only page produced and the markup change that fixed each; name the three layers of evidence you assembled (validator, DOM checks, accessibility tree) and what each one can catch that the others cannot; and say which roles header, aside and footer become in the tree.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check