Track 03 · Lesson 2 of 8Building for everyone

Track 03 · Building for everyone

Semantic HTML

Lesson 2 of 8· 6 min

Semantic elements say what something is, not just how it looks. The two versions below look the same, but browsers, search engines and screen readers understand them very differently.

Same look, different meaning

Switch versions and watch the right side

The markup

<html>
<body>
  <div class="header">
    <div class="logo">Bookly</div>
    <div class="nav">
      <span class="link" onclick="go('/')">Home</span>
      <span class="link" onclick="go('/books')">Books</span>
    </div>
  </div>
  <div class="main">
    <div class="title">New this week</div>
    <div class="subtitle">Fiction</div>
    <img src="cover.jpg">
    <div class="btn" onclick="addToCart()">Add to cart</div>
  </div>
  <div class="footer">© Bookly</div>
</body>
</html>

What you see (identical either way)

BooklyHomeBooks

New this week

Fiction

Add to cart

© Bookly

What assistive tech and browsers understand

Switch to “Semantic HTML” and watch the list fill in.

What you get for free#

A div with a click handler looks like a button, but that's all it does. A real button:

  • can be reached with Tab and pressed with Enter or Space,
  • is announced as "button" by screen readers,
  • submits forms, can be disabled, and shows a focus ring.

Rebuilding all of that on a div takes a role, a tabindex, two key handlers and state attributes, and it's easy to get wrong. The element already does it.

The elements that matter most#

  • Landmarks: header, nav, main, aside, footer. Screen reader users jump between them like chapters.
  • Headings: h1 to h6, in order, one h1 per page. They're how people skim, with eyes or a screen reader.
  • Controls: button for actions, a href for going somewhere, label paired with every input.
  • Lists and tables for content that really is a list or a table.

Check yourself

A clickable div says “Add to cart”. What's wrong with it?