Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

HTML
HTML
0/10 completed
Beginner
Your first web pageText, links and imagesLists and tablesForms
Intermediate
Semantic HTMLAccessibility basicsSEO and meta tags
Advanced
Images, video and embedsModern HTML: dialog, details and more
Pro
Performance and best practices
Tracks / HTML / Intermediate

Semantic HTML

Semantic means "having meaning". Semantic HTML uses elements that describe what content is, not how it looks. A <div> says nothing; a <nav> says "this is navigation".

Why it matters

  • Accessibility: screen readers let users jump straight to the <main> content, the <nav>, or the next heading.
  • SEO: search engines understand your page structure better.
  • Maintainability: <article> is far easier to read than <div class="post-wrapper-2">.
  • Free features: reader mode, browser outlines and keyboard behaviour all rely on semantics.

"Div soup" vs semantic HTML

html
<!-- ✗ Div soup -->
<div class="header">
  <div class="logo">MySite</div>
  <div class="menu">…</div>
</div>
<div class="content">
  <div class="post">…</div>
</div>
<div class="footer">…</div>

The landmark elements

HTML · CSS · live preview
Preview
Element Use it for
<header> Introductory content for the page or a section (logo, title, nav)
<nav> Major navigation link blocks
<main> The main content: one per page, unique to that page
<article> Self-contained content that makes sense on its own (blog post, product card, comment)
<section> A thematic group of content, normally with a heading
<aside> Related but secondary content (sidebar, callout)
<footer> Footer for the page or a section

Choosing the right element

Ask in order:

  1. Is it navigation? → <nav>
  2. Could it be shared on its own (syndicated, embedded)? → <article>
  3. Is it a themed group with a heading? → <section>
  4. Is it tangential to the main content? → <aside>
  5. None of the above, and it's just for styling? → <div> (that's fine!)

<div> and <span> aren't bad. They're the right choice when no semantic element fits: wrappers for layout and styling hooks.

Other meaningful elements

HTML · CSS · live preview
Preview

Buttons vs links

This is one of the most common mistakes in real codebases:

  • Link <a href>: goes somewhere (a new URL or page).
  • Button <button>: does something (submits, opens a menu, toggles, deletes).
html
<!-- ✗ Never: not keyboard accessible, no role, no focus -->
<div onclick="save()">Save</div>

<!-- ✓ Free keyboard support (Enter/Space), focus, and screen-reader role -->
<button type="button" onclick="save()">Save</button>

Practice

Convert this div soup into semantic HTML (keep the content the same):

HTML · CSS · live preview
Preview
✎ Check your understanding

1.How many <main> elements should a page normally have?

2.Clicking an element deletes an item. Which element should it be?

← Forms