Use Markup to Convey Information, Structure, and Relationships
Why It Matters
Screen readers and other assistive technologies rely on the underlying code structure, not just the visual appearance, to interpret content. Using semantic HTML allows these technologies to understand, for example, that a piece of text is a heading, an item belongs to a list, or which header cell corresponds to a data cell in a table. This provides crucial context that is lost if only non-semantic elements (<div>, <span>) with CSS styling are used.
Fixing the Issue
Use native HTML elements according to their semantic meaning. Use <h1>–<h6> for headings, <ol>, <ul>, and <li> for lists, <table>, <thead>, <tbody>, <th>, and <tr>/<td> for data tables (ensuring <th> elements have appropriate scope attributes or use id/headers), <label> for form labels, <nav> for navigation blocks, <main> for main content, <aside> for sidebars, etc. Avoid using HTML elements solely for their default styling; use CSS for presentation. Use ARIA roles and properties to supplement semantics only when native HTML is insufficient (e.g., for custom widgets).
Good Code Example
Using semantic HTML to convey structure and relationships:
-
<h2>Shopping List</h2> <ul> <li>Apples</li> <li>Oranges</li> <li>Milk</li> </ul> <table> <caption>Nutritional Information</caption> <thead> <tr> <th scope="col">Food</th> <th scope="col">Calories</th> <th scope="col">Fat (g)</th> </tr> </thead> <tbody> <tr> <th scope="row">Apple</th> <td>95</td> <td>0.3</td> </tr> <tr> <th scope="row">Banana</th> <td>105</td> <td>0.4</td> </tr> </tbody> </table> <label for="email-addr">Email:</label> <input type="email" id="email-addr">
-
Shopping List
- Apples
- Oranges
- Milk
Nutritional Information Food Calories Fat (g) Apple 95 0.3 Banana 105 0.4
Bad Code Example
Using non-semantic elements and CSS, hiding structure from assistive technology:
-
<div style="font-weight: bold; font-size: 1.2em;">Shopping List</div> <div>- Apples</div> <div>- Oranges</div> <div>- Milk</div> <div> <span style="font-weight: bold;">Food</span> <span style="font-weight: bold; margin-left: 10px;">Calories</span> </div> <div> <span>Apple</span> <span style="margin-left: 10px;">95</span> </div> <span>Email:</span> <input type="email" id="email-addr">
-
Shopping List– Apples– Oranges– MilkFood CaloriesApple 95Email:
