Phase 1 — HTML
Lesson 0002 • Beginner

Semantic HTML

Stop using <div> for everything. Learn the HTML tags that tell the browser (and Google) what your content actually means.

1. What Does "Semantic" Mean?

Semantic = "relating to meaning." In HTML, semantic tags are elements that clearly describe their purpose to both the browser and the developer reading the code.

Compare these two approaches:

❌ non-semantic.html
<div id="header">
  <div id="nav"> ... </div>
</div>
<div id="main-content">
  <div class="article"> ... </div>
</div>
<div id="footer"> ... </div>
✅ semantic.html
<header>
  <nav> ... </nav>
</header>
<main>
  <article> ... </article>
</main>
<footer> ... </footer>

Both produce the same visual result. But the semantic version is:

Source: MDN — Semantics in HTML

Key Insight

Professional developers always use semantic HTML. Using <div> for everything is the hallmark of someone who learned from outdated tutorials. When you go to a job interview, clean semantic HTML signals that you know what you're doing.

2. The Semantic Page Layout

Here is the standard layout that almost every professional website uses. Memorize this structure — you'll use it in every project you build:

semantic-layout.html
<body>

  <header>
    <!-- Site logo, site name, navigation -->
    <nav>
      <!-- Navigation links go here -->
    </nav>
  </header>

  <main>
    <!-- The primary content of the page -->

    <section>
      <!-- A thematic grouping of content -->
    </section>

    <article>
      <!-- A self-contained piece (blog post, product card) -->
    </article>

  </main>

  <aside>
    <!-- Sidebar content (related links, ads) -->
  </aside>

  <footer>
    <!-- Copyright, contact info, social links -->
  </footer>

</body>

3. Each Semantic Tag Explained

Semantic Elements Glossary

<header>
Introductory content — logo, site name, and navigation. Usually at the top of every page.
<nav>
Navigation links. Tells screen readers: "This is a menu." Nest it inside <header> typically.
<main>
The primary, unique content of the page. There must be only one <main> per page.
<section>
A thematic group of related content. Think: "About Us" section, "Features" section, "Pricing" section.
<article>
A self-contained, independently distributable piece of content. Think: blog post, product card, news story.
<aside>
Content tangentially related to the main content — sidebars, pull quotes, related links.
<footer>
Closing content — copyright notice, contact info, social media links. Usually at the bottom.
<figure> + <figcaption>
An image (or diagram) with a caption. Better than a bare <img> because it groups the image with its description.

4. Section vs. Article vs. Div — When to Use What

This is the most common point of confusion for beginners. Here's the decision rule:

Question to Ask If YES, Use
Could this content be syndicated independently (e.g., posted on another site)? <article>
Is this a thematic group with a heading (e.g., "Features", "Pricing")? <section>
Does this grouping have no semantic meaning — it's purely for styling? <div>
💡 Rule of Thumb If you're about to write <div>, pause and ask: "Is there a semantic tag that describes what this content is?" If yes, use the semantic tag. If it's purely a styling wrapper, <div> is fine.

5. The <title> Tag — Why It Matters More Than You Think

In your Lesson 1 practice, you used <title>Document</title> — the VS Code default. Here's why that matters:

Good titles are: Descriptive, concise (50-60 characters), and include your most important keyword. Examples:

Source: MDN — The <title> element

6. Real-World Example: A Portfolio Page

Here's a complete, semantic HTML page for a developer portfolio. Study the structure — every tag has a reason.

portfolio.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Altamash — Full Stack Developer</title>
</head>
<body>

  <header>
    <h1>Altamash</h1>
    <nav>
      <a href="#about">About</a>
      <a href="#skills">Skills</a>
      <a href="#projects">Projects</a>
      <a href="#contact">Contact</a>
    </nav>
  </header>

  <main>

    <section id="about">
      <h2>About Me</h2>
      <p>I am a full stack developer learning to build
        modern web applications.</p>
    </section>

    <section id="skills">
      <h2>Skills</h2>
      <ul>
        <li>HTML & CSS</li>
        <li>JavaScript</li>
        <li>React & Next.js</li>
      </ul>
    </section>

    <section id="projects">
      <h2>Projects</h2>
      <article>
        <h3>The Nawaab's Restaurant</h3>
        <p>A premium restaurant website built with
          Next.js and Tailwind CSS.</p>
      </article>
    </section>

    <section id="contact">
      <h2>Contact</h2>
      <p>Email: <a href="mailto:hello@example.com">hello@example.com</a></p>
    </section>

  </main>

  <footer>
    <p>&copy; 2026 Altamash. All rights reserved.</p>
  </footer>

</body>
</html>

Notice how reading this code, you immediately understand the page layout — even without seeing it in a browser. That's the power of semantic HTML.

Interactive Practice Zone

Test your understanding of semantic HTML elements.

Question 1: Which semantic tag should wrap the main navigation links of a website?
Question 2: How many <main> elements are allowed on a single HTML page?
Question 3: You want to group an "About Us" section with a heading. Which tag fits best?
Question 4: A blog post that could be shared on its own should be wrapped in:
Question 5: Why should you avoid using <div> for everything?
0/5

Quiz Completed!

Come back and retry this quiz tomorrow — spaced repetition builds permanent knowledge.

7. Build Challenge: Your Portfolio Page

This is the important part. Create a new file and build a semantic portfolio page. Here's exactly what to include:

  1. Create a file called practices/lesson2-portfolio.html
  2. Use the full HTML5 document structure (from Lesson 1 — type it from memory)
  3. Give it a proper <title> (not "Document"!)
  4. Build this structure using only semantic tags:
    • <header> with your name in an <h1> and a <nav> with 3-4 links
    • <main> containing:
      • An "About Me" <section>
      • A "Skills" <section> with a list
      • A "Projects" <section> with at least one <article> inside
    • <footer> with a copyright line
  5. Open it in your browser and check that it renders correctly
⚠️ The Real Test Do NOT copy the example code from Section 6 above. Type it yourself from understanding. If you get stuck, re-read the semantic elements glossary, then try again. Struggling is how your brain forms durable memory.

Primary Source: For a deeper dive into every semantic element, read MDN: Content Sectioning Elements.

Finished the build? Stuck on something? Come back and show me your code — I'll review it and tell you what's next.