Sub topic 16
Checking Your Markup with Devtools and Validators
This chapter assumes you know basic HTML syntax, can open your browser's developer tools, and have read the earlier chapters on landmarks, headings, forms and ARIA. Here you will learn how to verify that your markup says what you meant. You will use three kinds of tools: a validator, the browser's accessibility inspector, and a few manual checks.
Why checking matters
Browsers are forgiving. A page with a <div> where a <button> belongs looks fine on screen. Nothing throws an error. The problems only show up when someone uses a keyboard or a screen reader. So you need tools that look at meaning, not just appearance.
No single tool catches everything. Each one answers a different question:
| Tool | Question it answers | What it misses |
|---|---|---|
| HTML validator | Is the syntax and nesting legal? | Whether the elements fit the content |
| Accessibility tree inspector | What does assistive technology see? | Whether that is what you intended |
| Automated audit (Lighthouse, axe) | Which known patterns fail? | Most judgment calls, such as a wrong heading level that is still a number |
| Keyboard and screen reader test | Can a person actually use it? | Nothing in principle, but it is slow |
Step 1: Validate the syntax
The W3C Nu HTML Checker (validator.w3.org/nu) parses your page the way the HTML standard describes. It accepts a URL, an uploaded file, or pasted text. It reports errors and warnings with line numbers.
Many semantic mistakes are also validity errors. Take this page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Checker demo</title>
</head>
<body>
<main>
<h1>Demo</h1>
<p>Intro text.
<div>A block inside a paragraph</div>
</p>
<ul>
<div>Not a list item</div>
</ul>
<button><a href="/next">Next</a></button>
<img src="photo.jpg">
<label for="name">Name</label>
<input id="nmae" type="text">
</main>
<main>
<p>A second main landmark.</p>
</main>
</body>
</html>The validator flags several problems here:
- The
<div>closes the<p>automatically, so the later</p>is a stray end tag. - A
<div>is not allowed as a direct child of<ul>. - An
<a>with anhrefcannot be nested inside a<button>, because interactive content may not contain other interactive content. - The
<img>has noaltattribute. - The
for="name"on the label points to no element, because the input's id is misspellednmae. - A visible page may have only one
<main>that is not hidden.
Treat errors as things to fix. Treat warnings as things to read. A warning such as "Section lacks heading" is often a real semantic hint: a <section> with no heading usually should be a <div>.
What the validator cannot tell you
The validator checks rules, not intent. This markup is valid:
<h1>Our Services</h1>
<h4>Web design</h4>
<p><b>Important:</b> prices change.</p>
<div onclick="go()">Continue</div>It skips from h1 to h4, uses <b> where <strong> was meant, and builds a fake button. The validator passes all of it. You need the next tools to find these.
Step 2: Inspect the accessibility tree
Every major browser builds an accessibility tree from the DOM. This is the structure that screen readers and other assistive technology read. Each node has a role, an accessible name, and states.
In Chrome or Edge:
- Open devtools and select an element in the Elements panel.
- Open the Accessibility pane (under the Computed or Styles tabs, or use the "Accessibility" tab).
- Read the Role, Name, and any states such as
focusableorexpanded. - Use "Enable full-page accessibility tree" to browse the whole tree.
Firefox has an Accessibility panel with a tree view and an option to show tabbing order. Safari offers an Accessibility section in the Elements sidebar.
Check these things for each element:
- Role matches intent. A real button shows
button. A styled div showsgeneric. - Name is present and correct. A form input should show the label text as its name. An image should show its
alttext. - Landmarks appear once where expected. Look for
banner,navigation,main,complementary, andcontentinfo. - Headings appear with the right level. The tree lists each heading with its level.
For the demo page above, the misspelled input would show an empty name, and the <div onclick> would show as generic with no focusable state.
Step 3: Run an automated audit
Lighthouse (built into Chrome devtools) and the axe DevTools extension scan the page against a list of known failures. They are fast and catch the mechanical problems:
- Missing
alttext - Form controls without labels
- Buttons or links without an accessible name
- Skipped heading levels (reported by axe as a best-practice warning)
- Invalid ARIA roles or attributes
- Missing
langon<html> - Duplicate ids
Lighthouse gives a score. Do not chase the number. A score of 100 means no automated rule failed. It does not mean the page is accessible. Automated tools cover only a portion of the issues that affect real users, so treat a pass as "no known pattern found."
Step 4: Test by hand
Some problems only appear when you use the page. Two quick checks cover most of them.
Keyboard pass
Put your mouse aside and press Tab repeatedly. Ask:
- Can you reach every link, button, and form control?
- Does the focus order follow the reading order?
- Is the focus indicator always visible?
- Do Enter and Space activate buttons, and Enter activate links?
- Can you open and close
<details>and<dialog>without a mouse?
A <div onclick> fails the first check because it never receives focus.
Headings and landmarks pass
Screen readers let users jump between headings and landmarks. You can simulate this by reading the heading list. The quickest way is a short script you paste into the devtools console:
// Print the heading outline and flag skipped levels.
let previous = 0;
document.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((heading) => {
const level = Number(heading.tagName[1]);
const skipped = previous && level > previous + 1 ? " <-- skipped level" : "";
console.log(`${" ".repeat(level - 1)}h${level}: ${heading.textContent.trim()}${skipped}`);
previous = level;
});
// Count landmarks that should appear once.
["main", "body > header", "body > footer"].forEach((selector) => {
console.log(`${selector}: ${document.querySelectorAll(selector).length}`);
});The output reads like a table of contents. If it does not make sense on its own, the heading structure needs work. Going back up several levels, for example from h4 to h2, is fine. Only skipping downward is a problem.
For a real screen reader test, try NVDA on Windows (free), VoiceOver on macOS (built in), or TalkBack on Android. Even ten minutes with one of them reveals issues no tool reports.
A repeatable workflow
Run the checks in this order, because each step makes the next one easier to read.
Fix validator errors first. A broken nesting structure can change how the browser builds the DOM, which makes every later check report on a tree you did not write.
Common pitfalls when checking
- Validating the source, not the rendered page. If JavaScript builds your page, the validator sees only the initial HTML. Inspect the live DOM in devtools for the rendered result, or copy the rendered HTML into the validator.
- Trusting the score. A perfect Lighthouse score can sit on top of a page with a poor heading structure.
- Ignoring warnings. Warnings about empty headings or sections without headings point to real semantic gaps.
- Fixing the tool, not the markup. Adding
role="button"to a<div>may silence an audit but still leaves the keyboard problem. Replace the element instead. - Checking only one state. Open the menu, the dialog, and the error state of a form, then check each again. Content that appears later may have its own problems.
Exercises
Exercise
A page passes the W3C validator with no errors, but a keyboard user cannot activate its "Buy now" control, which is written as <span class="btn" onclick="buy()">Buy now</span>. Why did the validator not report this, and which two checks from this chapter would reveal it? What is the fix?
Show answer
The validator checks syntax and nesting rules, and a span with an onclick attribute is legal HTML. It cannot know the span is meant to be a button. The accessibility tree inspector would show the role as generic with no focusable state, and a keyboard pass would show that Tab skips it. The fix is to replace it with <button type="button" onclick="buy()">Buy now</button>, which is focusable, responds to Enter and Space, and has the button role.
Exercise
In the accessibility inspector, a <header> element you placed inside an <article> shows the role generic instead of banner. Is this a bug? Explain.
Show answer
It is not a bug. A header or footer maps to the banner or contentinfo landmark only when it is not a descendant of article, section, main, aside, or nav. Inside an article it describes that article's introductory content and has no landmark role. If you wanted a page-level banner, move the header to be a direct child of body.