Sub topic 15
Common mistakes and how to fix them
This chapter assumes you know the landmark elements, heading levels, text-level elements, native form controls and the idea of the accessibility tree from earlier chapters. It collects the errors that appear most often in real pages. For each one it shows the symptom, the cause and the fix.
Why the same mistakes keep appearing
Most semantic errors come from one habit: choosing an element for how it looks in the browser instead of what the content is. Browsers hide the damage. A div styled with CSS looks like a button, and a b looks like emphasis. Only keyboard users, screen reader users, search crawlers and reader modes notice the difference.
The diagram shows a quick way to diagnose a suspect element.
Mistake 1: Clickable divs and spans
A div with an onclick handler is not focusable, ignores Enter and Space, and has no role. A screen reader announces it as plain text.
<!-- Avoid -->
<div class="btn" onclick="save()">Save</div>
<!-- Prefer -->
<button type="button" onclick="save()">Save</button>The same applies to links. An a without an href is not focusable and is not exposed as a link. The reverse mistake is also common: <a href="#" onclick="openMenu()"> uses a link for an action. Use a link when the click goes somewhere, and a button when it does something on the current page.
Fix the look with CSS, not with markup. Buttons accept nearly any styling:
<style>
.btn {
font: inherit;
padding: 0.5rem 1rem;
border: 0;
border-radius: 4px;
background: #0a58ca;
color: #fff;
}
.btn:focus-visible { outline: 3px solid #ffbf47; }
</style>
<button class="btn" type="button">Save</button>Do not remove the focus outline without providing a replacement. A visible focus style is part of operable markup.
Mistake 2: Picking headings by size
Authors often use an h4 because the default size looks right, or an h1 in the header of every component. Screen reader users navigate by heading level, so the levels need to describe structure.
<!-- Avoid: levels chosen for size, level skipped -->
<h1>Site name</h1>
<h4>Latest news</h4>
<h2 style="font-size: 0.9rem">Archive</h2>
<!-- Prefer: levels reflect structure, size comes from CSS -->
<h1>Latest news</h1>
<h2 class="small-heading">Archive</h2>Rules of thumb:
- Use one
h1that names the page's main topic. - Never skip a level when going deeper, so
h2is followed byh3, noth4. - Going back up several levels is fine, for example
h4followed byh2when a new major section starts. - Do not use a heading for a tagline or a bold label. Use a
p.
Mistake 3: Landmark misuse
Landmarks help users jump between regions. Overusing them makes the list noisy, and misusing them removes the value.
| Mistake | Why it hurts | Fix |
|---|---|---|
| Two or more visible `main` elements | The page has one primary content region | Keep one `main`, or hide the extras with the `hidden` attribute |
| `nav` around every group of links | The landmark list fills with minor items | Reserve `nav` for major navigation blocks such as the primary menu |
| Several `nav` elements with no labels | Users hear "navigation" several times and cannot tell them apart | Add `aria-label`, for example `aria-label="Breadcrumb"` |
| Content outside any landmark | Users who navigate by landmark skip it | Put page content inside `header`, `main`, `aside` or `footer` |
| `aside` used for any narrow column | `aside` means tangentially related content | Use `div` if the column is part of the main content |
A related point: header and footer only map to the page-level banner and contentinfo landmarks when they are not inside article, section, main, aside or nav. Inside those, they are just the heading area or footer of that section. That is correct behavior, not a bug.
Mistake 4: Sections without meaning
A section with no heading is a div with a longer name. A section used only as a styling wrapper adds nothing.
<!-- Avoid: section as a styling hook -->
<section class="card-wrapper">
<p>Thanks for visiting.</p>
</section>
<!-- Prefer: div for pure layout, section when it has a heading -->
<div class="card-wrapper">
<p>Thanks for visiting.</p>
</div>
<section>
<h2>Pricing</h2>
<p>Plans start at $5 a month.</p>
</section>Test for article: could the content be syndicated or pulled out on its own, such as a post, a comment or a product card? If so, article fits. If it is a thematic part of a larger whole, use section with a heading.
Mistake 5: Presentation elements and misused text-level tags
bandiare not wrong in every case, but they carry no importance or stress. Usestrongfor importance andemfor stress. Useifor a technical term or a foreign phrase, andbfor a keyword that needs attention without extra importance.blockquoteis for quotations, not indentation. Use CSS margins for indentation.brseparates lines within one unit, such as a poem or an address. Do not use it to space paragraphs or to build lists.uandfontcome from presentation-era markup. Use CSS instead.
<!-- Avoid: br as paragraph spacing and fake list -->
First item<br>Second item<br>Third item<br><br><br>
Next paragraph
<!-- Prefer -->
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
<p>Next paragraph</p>Removing bullets with list-style: none can cause some browsers to stop announcing the element as a list. If the content is really a list, keep the ul and add role="list" to the styled element, or check it with a screen reader.
Mistake 6: Tables and forms
For tables, the errors are:
- Using
tablefor page layout. Use CSS grid or flexbox. - Using
tdfor header cells. Usethwithscope. - Leaving out
caption, which names the table for everyone.
For forms:
- A
placeholderstands in for alabel. The placeholder disappears when typing starts, often has low contrast, and is not a reliable accessible name. - A
labelthat is not linked. Either wrap the control or matchforto the control'sid. - Related radio buttons or checkboxes with no
fieldsetandlegend, so users hear options without the question. - A
divwith a click handler used for submit. Usebutton type="submit".
<!-- Avoid -->
<input type="text" placeholder="Email">
<!-- Prefer -->
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email" required>Mistake 7: Redundant or conflicting ARIA
ARIA changes what assistive technology hears. It adds no behavior. A role="button" on a div still needs focus, key handling and a name. Common problems:
<button role="button">or<nav role="navigation">repeats what the element already says.rolethat contradicts the element, such as<h2 role="tab">, replaces the heading meaning.aria-labelon adivorspanwith no role is often ignored.aria-hidden="true"on a focusable element hides it from the accessibility tree but keeps it reachable by keyboard, creating a focus trap for screen reader users.
The first rule of ARIA is to use native HTML when it exists. Reach for ARIA when no native element matches, such as for a tab list or a live status message.
Mistake 8: Images with missing or poor alternatives
Every img needs an alt attribute. If the image carries information, describe its meaning. If it is decorative, use alt="" so assistive technology skips it. Avoid text such as "image of" and file names. A missing alt makes some screen readers read the file URL aloud.
A review checklist
Use this when you audit a page:
- Tab through the page. Every interactive item should be reachable, show focus and work with the keyboard.
- Open the accessibility tree in devtools. Check names and roles of controls.
- List the headings. Read them alone to see if they outline the page.
- List the landmarks. Check there is one
mainand that repeated landmarks are labeled. - Run the W3C Nu validator. It reports unclosed elements, invalid nesting, such as a
buttoninside ana, and missing attributes.
Exercise
A teammate wrote <div class="button" role="button" tabindex="0" onclick="submitOrder()">Place order</div> inside a form. Name two things that still do not work, and give the fix.
Show answer
The div does not respond to Enter or Space because the handler only listens for clicks, and it does not submit the form on its own. It also lacks built-in disabled behavior and form association. Replace it with <button type="submit">Place order</button>, which is focusable, activates with Enter and Space, has the button role and submits the form without ARIA or extra JavaScript.
Exercise
A page has h1 for the site name, then h4 for "Latest news" because the h2 and h3 sizes were too large. How do you fix it without changing how it looks?
Show answer
Set the heading to the level that matches the structure, for example h2 under a page h1 or make "Latest news" the h1, and use a CSS class to set the font size. The level describes structure, and CSS controls size.