Sub topic 15
Common mistakes and how to fix them
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 native interactive elements. Here you will learn to recognize the mistakes that appear most often in real pages, and the fix for each one.
Mistakes that come from choosing by appearance
Most semantic errors share one cause: the author picked an element for how it looks by default. The element should be picked for what the content is. Appearance belongs to CSS.
| Mistake | Why it hurts | Fix |
|---|---|---|
| `<h3>` used for small bold text | Creates false headings in the screen reader heading list | Use `<p>` or `<strong>`, and style it with CSS |
| Skipped heading levels (`h1` then `h4`) | Breaks the outline that people navigate by | Use the next level down, and resize with CSS |
| `<blockquote>` used to indent text | Declares a quotation that does not exist | Use a `<p>` with a CSS margin |
| `<table>` used for page layout | Announces data cells where there is no data | Use CSS grid or flexbox |
| `<b>` and `<i>` chosen for importance | They carry no meaning for importance or stress | Use `<strong>` and `<em>` |
Mistakes with generic elements
A div with a click handler looks like a button but is not one. It cannot receive focus, ignores Enter and Space, and has no role.
<!-- Broken -->
<div class="btn" onclick="save()">Save</div>
<!-- Fixed -->
<button type="button" onclick="save()">Save</button>The same applies to links. An <a> with no href is not focusable, and a link that only runs JavaScript should usually be a button. Use a when the action goes to a location, and button when it does something on the current page.
Mistakes with structure
Three structural errors come up repeatedly:
- Several
mainelements visible on one page. A page has onemain. - Every region wrapped in
div, so no landmarks exist. - Multiple
navelements with no labels. Give each one a distinctaria-label, such as "Primary" and "Footer", so users can tell them apart.
<nav aria-label="Primary">
<ul>
<li><a href="/articles">Articles</a></li>
</ul>
</nav>
<nav aria-label="Footer">
<ul>
<li><a href="/privacy">Privacy</a></li>
</ul>
</nav>Mistakes with forms and ARIA
A placeholder is not a label. It disappears when the user types and is not a dependable accessible name. Connect each control to a real label with matching for and id values.
<!-- Broken: placeholder only -->
<input type="email" placeholder="Email address">
<!-- Fixed -->
<label for="email">Email address</label>
<input id="email" name="email" type="email" placeholder="[email protected]">ARIA is the other common source of errors. Adding role="button" to a div only changes what is announced. It adds no focus and no keyboard handling, so you would still have to write all of that yourself.
A repair workflow
After each fix, press Tab through the page and open the accessibility panel in your devtools. Check that the role, name and focus order match what you intended.
Exercise
A page has <span class="link" onclick="go('/pricing')">Pricing</span> in its menu. Name two things a keyboard user cannot do with it, and write the fix.
Show answer
The user cannot focus it with Tab and cannot activate it with Enter. It also has no link role, so screen readers do not announce it as a link. The fix is <a href="/pricing">Pricing</a>, because the action goes to another location.