HTML and CSS · Lesson 4 of 12
Semantic HTML and accessibility
"Semantic" means using the element that says what something is. It costs nothing, and it makes your page work for screen readers, search engines and keyboard users.
The landmarks
Instead of a page made only of <div>s, use <header>, <nav> (main menus), <main> (the page's main content, once), <article> (something that stands alone: a post, a product), <section> (a themed group with a heading), <aside> (related, but not the main thing) and <footer>. Screen-reader users jump between these landmarks the way you scan with your eyes.
Buttons, links and the keyboard
A link (<a href>) goes somewhere; a button (<button>) does something on the page. Both work with the keyboard for free: Tab to reach them, Enter (and Space, for buttons) to use them. A <div onclick> does neither, which is why it's the most common accessibility bug.
Keep headings in order (h1, then h2, then h3), give images alt text and inputs labels, and make sure text has enough contrast against its background.
Your turn
Turn this page made of divs into semantic HTML: a header with a nav, a main with an article, and a footer.
Show a solution
<header>
<strong>Shop</strong>
<nav><a href="#">Home</a> <a href="#">Cart</a></nav>
</header>
<main>
<article>
<h1>Blue backpack</h1>
<p>₹1,299</p>
</article>
</main>
<footer>Contact us</footer>In the interview
What is semantic HTML, and why does it matter?
Using elements for their meaning (nav, main, article, button) rather than generic divs. Screen readers use it to navigate, search engines use it to understand the page, and you get keyboard behaviour for free.
section vs article vs div?
article is complete on its own (a post, a comment, a product card). section groups related content under a heading within something bigger. div has no meaning: use it only as a hook for styling.
Why not use a div with a click handler as a button?
It can't be reached with Tab, doesn't respond to Enter or Space, and isn't announced as a button. A real <button> does all of that with no extra code.