1. How the Web Works & Semantic HTML5

HTML5 Anatomy & Semantic Structure

Build clean, accessible, search-friendly web pages from scratch: understand <!DOCTYPE html>, <head> metadata, semantic landmarks, heading hierarchy, links, lists, and responsive images.

6 min readUpdated 2026-11-29
In This Lesson
  • Read and write a complete HTML5 boilerplate with <head> metadata and <body> content
  • Structure pages accessibly using semantic tags like <header>, <nav>, <main>, <article>, and <footer>
  • Build clean heading hierarchies, safe external links, structured lists, and accessible images

HTML (HyperText Markup Language) is not a programming language with loops or if statements—it is a structural language. HTML uses descriptive tags wrapped in angle brackets (<p>, <h1>, <button>) to tell browsers and screen readers what each piece of content means.

Before styling anything with CSS, great web developers make sure their raw HTML makes complete sense on its own.

Complete Anatomy of an HTML5 Document

You do not need any build tool or framework to run HTML. Save the template below as index.html on your computer and double-click it to open it in any browser:

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My Portfolio — Alex Rivera</title>
    <meta name="description" content="Web developer portfolio and learning notes." />
  </head>
  <body>
    <header>
      <h1>Alex Rivera</h1>
      <nav aria-label="Primary navigation">
        <a href="#about">About</a>
        <a href="#projects">Projects</a>
      </nav>
    </header>

    <main>
      <section id="about">
        <h2>About Me</h2>
        <p>I build clean, fast websites using HTML, CSS, and JavaScript.</p>
      </section>
    </main>

    <footer>
      <p>Built while learning at Yadav Academy.</p>
    </footer>
  </body>
</html>

Every section in that file has a specific job:

  • <!DOCTYPE html>: Tells the browser to use modern HTML5 standards instead of legacy compatibility modes.
  • <html lang="en">: Wraps the entire document and declares the primary language so screen readers pronounce words accurately and Google indexes language correctly.
  • <head>: Holds invisible metadata about the page—its character encoding (UTF-8 so emojis and accents never scramble), mobile viewport sizing, browser tab <title>, and linked CSS files.
  • <body>: Holds everything visible on the screen.
Never Skip the Viewport Meta Tag

Always include <meta name="viewport" content="width=device-width, initial-scale=1.0" /> inside <head>. Without it, mobile phones pretend they have a tiny 980px desktop screen and zoom everything out to unreadable miniature text!

Why Semantic HTML5 Tags Beat Generic <div> Soup

Early websites wrapped every block inside meaningless <div class="header">, <div class="sidebar">, and <div class="bottom">. Visually that works, but screen readers (used by blind visitors) and search engines have zero clue which <div> holds the main article versus repeated navigation links.

Modern HTML5 solves this with semantic landmarks whose tag names clearly communicate their role:

Semantic TagRole on the PageReal Example
<header>Introductory banner for a page or sectionSite logo + title bar
<nav>Group of primary navigation linksTop menu bar or sidebar index
<main>Unique primary content of the document (only 1 per page)Lesson body or dashboard
<section>Thematic grouping of related content, usually with its own headingFeatures grid or FAQ section
<article>Self-contained piece of content that could stand aloneBlog post card or news story
<aside>Supporting sidebar content related indirectly to <main>Table of contents or glossary box
<footer>Closing metadata at the bottom of a page or sectionCopyright, contact, links

Keep <div> and <span> strictly for pure visual grouping wrappers when no meaningful semantic tag fits (for example, wrapping two cards to align them side-by-side with Flexbox).

Headings Define an Outline—Not Font Size

Think of headings like a book's table of contents:

  • Use one <h1> per page for the main topic.
  • Step down cleanly to <h2> for major sections and <h3> for subsections—never jump from <h1> straight to <h4> just because you want smaller text (use CSS for font sizing!).
html
<!-- Unordered (bulleted) list of helpful links -->
<ul>
  <li><a href="#projects">Jump to Projects section on this page</a></li>
  <li><a href="about.html">Open local page in same folder</a></li>
  <li>
    <a href="https://developer.mozilla.org" target="_blank" rel="noopener noreferrer">
      MDN Web Docs (opens safely in new tab)
    </a>
  </li>
</ul>

Notice rel="noopener noreferrer" alongside target="_blank": whenever a link opens a new tab to another website, noopener blocks the external page from accessing or hijacking your original browser tab via JavaScript.

Accessible Images (<img>) and Preventing Layout Jump

html
<figure>
  <img
    src="desk-setup.jpg"
    alt="Minimal wooden desk with laptop displaying HTML code"
    width="800"
    height="500"
  />
  <figcaption>Consistent semantic markup makes pages easier to style later.</figcaption>
</figure>

Two rules make images production-ready:

  1. Always write helpful alt text describing what the image shows (screen readers speak this aloud, and browsers show it if slow Wi-Fi fails to load the image). For purely decorative icons, pass empty alt="" so screen readers quietly skip them.
  2. Always provide width and height attributes so the browser reserves the exact vertical space before the photo finishes downloading, preventing the page text from jumping downward unexpectedly.
Using Clickable <div> Tags Instead of <button> or <a>

Never use <div onclick="...">Submit</div> or <span onclick="...">Read More</span>. Keyboard users pressing Tab cannot focus a <div>, and Enter won't trigger it! Use <a> when navigating to a URL, and <button> when triggering an action on the page.

Try It Live: Build a Semantic Profile Section

Edit the <main> section below to add a second <article> card inside <section> and an ordered list (<ol>) of your top three learning goals, then click Run & Preview:

HTML / CSS / JSLive HTML5 — Semantic Page Builder
Live Browser Preview

Practice Challenge: News Article Card

Build a semantic <article> block for a tech news headline with a publication <time datetime="2026-11-29">, a short summary paragraph, and an external "Read source" link that opens safely in a new tab.

Quick Checkpoints

Check Your Understanding

Which HTML5 tag should wrap the unique primary content of a page (and appear only once per document)?

Check Your Understanding

Why should external links with target='_blank' also include rel='noopener noreferrer'?