Skip to main content
HTML & CSS Foundations·Lesson 1 of 5

Semantic HTML

Semantic HTML means using elements that describe the meaning of your content, not just its appearance. Instead of wrapping everything in <div>, you use elements like <header>, <nav>, and <article> to communicate structure to browsers, screen readers, and search engines.

Why Semantics Matter

  • Accessibility: Screen readers use semantic elements to navigate pages. A <nav> is announced as navigation; a <div> is not.
  • SEO: Search engines understand your content hierarchy through semantic markup.
  • Maintainability: Semantic code is self-documenting and easier to read.

Document Structure

Every HTML page should follow a clear structural hierarchy:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scal=1.0">
  <title>My Website</title>
</head>
<body>
  <header>
    <nav>
      <a href="/">Home</a>
      <a href="/about">About</a>
    </nav>
  </header>

  <main>
    <article>
      <h1>Page Title</h1>
      <p>Main content goes here.</p>
    </article>
  </main>

  <footer>
    <p>&copy; 2026 My Website</p>
  </footer>
</body>
</html>

Key rules:

  • One <main> per page — it wraps your primary content.
  • <header> and <footer> can appear inside <article> or <section>, not just at the top level.
  • Use only one <h1> per page, then <h2> through <h6> in order. Never skip heading levels.

Sectioning Elements

Use these elements to group related content:

<section>
  <h2>Features</h2>
  <p>Each section should have a heading that describes its content.</p>
</section>

<article>
  <h2>Blog Post Title</h2>
  <time datetime="2026-03-12">March 12, 2026</time>
  <p>Articles are self-contained pieces of content that could stand alone.</p>
</article>

<aside>
  <h2>Related Links</h2>
  <ul>
    <li><a href="/guide">Beginner Guide</a></li>
  </ul>
</aside>
  • <section> groups thematically related content.
  • <article> wraps self-contained content (blog posts, comments, cards).
  • <aside> holds tangentially related content (sidebars, callouts).

Interactive Elements

HTML provides built-in interactive elements that work without JavaScript:

<details>
  <summary>Click to expand</summary>
  <p>This content is hidden until the user clicks the summary.</p>
</details>

<dialog id="my-dialog">
  <h2>Confirmation</h2>
  <p>Are you sure?</p>
  <form method="dialog">
    <button value="cancel">Cancel</button>
    <button value="confirm">Confirm</button>
  </form>
</dialog>

Accessible Forms

Forms are where accessibility matters most. Every input needs a label, and grouping related fields helps users understand the structure:

<form action="/register" method="post">
  <fieldset>
    <legend>Personal Information</legend>

    <label for="name">Full Name</label>
    <input type="text" id="name" name="name" required>

    <label for="email">Email</label>
    <input type="email" id="email" name="email" required>
  </fieldset>

  <fieldset>
    <legend>Preferences</legend>

    <label for="color">Favorite Color</label>
    <select id="color" name="color">
      <option value="">Choose one</option>
      <option value="red">Red</option>
      <option value="blue">Blue</option>
    </select>

    <label>
      <input type="checkbox" name="newsletter" value="yes">
      Subscribe to newsletter
    </label>
  </fieldset>

  <button type="submit">Register</button>
</form>

Key form rules:

  • Always pair <label> with inputs via for and id, or wrap the input inside the label.
  • Use <fieldset> and <legend> to group related fields.
  • Use the correct type attribute (email, tel, url, number) for built-in validation and mobile keyboards.
  • Prefer <button type="submit"> over <input type="submit">.

Text-Level Semantics

Choose elements based on meaning, not appearance:

ElementMeaningNot for
<strong>Important textJust making text bold
<em>Stressed emphasisJust making text italic
<mark>Highlighted/relevant textDecorative highlighting
<time>Dates and timesRandom numbers
<code>Inline codeMonospace styling
<abbr>AbbreviationsTooltips on random text
<p>
  The deadline is <time datetime="2026-04-01">April 1st</time>.
  This is <strong>critically important</strong>  please use
  <abbr title="HyperText Markup Language">HTML</abbr> correctly.
</p>

Common Mistakes

  1. Using <div> for everything — reach for semantic elements first.
  2. Skipping heading levels — going from <h1> to <h4> breaks the outline.
  3. Missing alt on images — every <img> needs alt. Use alt="" for purely decorative images.
  4. Using <a> without href — an anchor without href is not keyboard-focusable. Use <button> for actions.