Difficulty: Beginner
What is semantic HTML? Why does it matter for accessibility and SEO, and when do you still need ARIA?
Semantic HTML means choosing elements for what the content is rather than how it looks: <nav> for navigation, <button> for an action, <article> for a self-contained post, <h1>-<h6> for headings. Browsers turn these elements into roles in the accessibility tree, so screen readers, keyboards, search engines and reader modes understand the page without extra work. A page built from <div> and <span> can look identical but tells these tools nothing.
When the browser parses HTML it builds the DOM, and from it an accessibility tree. Each node gets a role, a name and a state. A <button>Pay ₹499</button> becomes role button, name "Pay ₹499", and it is focusable and fires on both Enter and Space for free. A <div onclick> becomes a generic node with no role, no keyboard support and no focus.
Landmark elements map to ARIA landmark roles that screen reader users jump between:
| Element | Implicit role | Notes |
|---|---|---|
<header> | banner | Only when not nested inside <article>, <section>, <main> etc. |
<nav> | navigation | Use for major navigation blocks, not every group of links |
<main> | main | One visible <main> per page |
<aside> | complementary | Related but secondary content |
<footer> | contentinfo | Same nesting rule as <header> |
<section> | region | Only becomes a landmark when it has an accessible name |
Search engines read the same structure. Google uses headings, link text, <main> content and lists to understand what a page is about and which parts are boilerplate. Semantic markup is not a magic ranking boost, but it removes ambiguity: a clear <h1>, a logical heading outline and real <a href> links (not divs with click handlers) make content easier to crawl and extract for featured snippets.
The first rule of ARIA is: if a native element does the job, use it. ARIA only changes what assistive technology hears; it adds no behaviour. Reach for it when HTML has no equivalent:
role="tablist", aria-selected, aria-controls)aria-live="polite" for "Item added to cart")aria-label="Close")aria-describedby, aria-invalid)Wrong ARIA is worse than none. role="button" on a div still needs tabindex="0", Enter and Space handlers and focus styles, which is why a plain <button> is almost always the better answer.
<h4> because it looked right)<section> as a styling wrapper; use <div> when there is no meaningdivs and spans instead of <button> or <a>alt on images, or writing "image of" in alt text; decorative images need alt=""<label>; placeholder is not a labeloutline: none and nothing to replace themOn a real product, such as a checkout flow on Flipkart or Swiggy, these details decide whether a keyboard or screen reader user can finish paying. Teams catch them with axe or Lighthouse audits in CI plus manual testing with NVDA, VoiceOver or TalkBack.
<!-- BAD: everything is a div, nothing has a role -->
<div class="header">
<div class="nav"><div onclick="go('/')">Home</div></div>
</div>
<div class="content">
<div class="title">Order summary</div>
<div class="btn" onclick="pay()">Pay ₹499</div>
</div>
<!-- GOOD: landmarks, headings and native controls -->
<header>
<nav aria-label="Primary">
<a href="/">Home</a>
</nav>
</header>
<main>
<article>
<h1>Order summary</h1>
<p>2 items, delivery in 30 minutes</p>
<button type="button">Pay ₹499</button>
</article>
</main>
<footer>
<p>© 2026 Example Foods</p>
</footer>
The semantic version exposes banner, navigation, main and contentinfo landmarks, a real heading and a focusable button that works with Enter and Space without any JavaScript.
<!-- Icon-only button needs an accessible name -->
<button type="button" aria-label="Close dialog">
<svg aria-hidden="true" focusable="false"><!-- x icon --></svg>
</button>
<!-- Announce cart updates without moving focus -->
<p aria-live="polite" id="cart-status">2 items in cart</p>
<!-- Connect hint and error text to the input -->
<label for="upi">UPI ID</label>
<input id="upi" name="upi" required
aria-describedby="upi-hint upi-error"
aria-invalid="true">
<p id="upi-hint">Example: name@okbank</p>
<p id="upi-error">Enter a valid UPI ID</p>
Each ARIA attribute here fills a gap native HTML cannot: naming an icon, announcing a live change and associating extra text with a field.
Semantic HTML, Landmark elements, Accessibility tree, ARIA roles, Screen readers, SEO