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)
Python 3 (for local server via python3 -m http.server)
π¬ 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.
Enhance your <head> section:
π‘ Comments in HTML use <!-- comment --> syntax.
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>
You learned that every HTML5 document requires:
<!DOCTYPE html> declaration
<html lang="en"> root element
<head> for metadata (charset, viewport, title)
<body> for all visible content
π Further Reading