Lab 01: HTML Structure & Semantics

🎯 Objective

Understand the fundamental structure of an HTML document including DOCTYPE, <html>, <head>, and <body> elements.

πŸ“š Background

Every HTML page follows a standard structure. The DOCTYPE declaration tells the browser which version of HTML is being used. HTML5 uses <!DOCTYPE html>. The <head> section contains metadata (invisible to users), while <body> contains visible content.

⏱️ Estimated Time

20 minutes

πŸ“‹ Prerequisites

  • A text editor (VS Code, Notepad++, or any plain text editor)

  • A web browser

πŸ› οΈ Tools Used

  • Python 3 (for local server via python3 -m http.server)

  • Any modern web browser

πŸ”¬ Lab Instructions

Step 1: Create your working directory

πŸ’‘ Keeping labs organized helps when reviewing your progress later.

Step 2: Create your first HTML file

Create a file named index.html with the following content:

πŸ’‘ <!DOCTYPE html> is not a tag β€” it's a declaration that tells browsers to use HTML5 standards mode.

Step 3: Understand the <head> section

The <head> contains:

  • <meta charset="UTF-8"> β€” Character encoding (supports all languages)

  • <meta name="viewport"> β€” Controls layout on mobile devices

  • <meta name="description"> β€” SEO description shown in search results

  • <title> β€” Tab title shown in browser

Step 4: Understand the <body> section

Everything inside <body> is rendered by the browser and visible to users.

Step 5: Validate the HTML using Python

πŸ“Έ Verified Output:

Step 6: Serve the page locally

Open your browser at http://localhost:8080 to see your page.

πŸ“Έ Verified Output: You should see "Hello, World!" as a large heading and the paragraph below it.

Step 7: Add more metadata

Enhance your <head> section:

πŸ’‘ Comments in HTML use <!-- comment --> syntax.

Step 8: Inspect with browser DevTools

Open your browser, right-click the page, select Inspect (or press F12). Explore the Elements panel to see the document tree.

πŸ“Έ Verified Output: The DevTools Elements panel shows the full DOM tree matching your HTML structure.

βœ… Verification

Run the Python validator on your file:

🚨 Common Mistakes

  • Missing DOCTYPE β€” Causes browsers to enter "quirks mode" with unpredictable rendering

  • Forgetting lang attribute β€” Important for accessibility and SEO

  • Putting content in <head> β€” Only metadata belongs in <head>, not visible content

  • Not closing tags β€” Always close tags like </html>, </head>, </body>

πŸ“ Summary

You learned that every HTML5 document requires:

  1. <!DOCTYPE html> declaration

  2. <html lang="en"> root element

  3. <head> for metadata (charset, viewport, title)

  4. <body> for all visible content

πŸ”— Further Reading

Last updated