HTML Document Structure
Every HTML file needs a specific structure — like a building needs a foundation before walls. Browsers read this structure to know how to display your page. Get this right and everything else becomes easy.
Full Structure Explained
<!-- 1. DOCTYPE: "Hey browser, I am HTML5" --> <!DOCTYPE html> <!-- 2. Root element: lang tells Google the language --> <html lang="en"> <!-- 3. HEAD: invisible to users, crucial for browser + Google --> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>CIWeb — Learn HTML Free</title> <meta name="description" content="Free HTML course with 22 lessons"/> </head> <!-- 4. BODY: everything the user actually sees --> <body> <h1>Welcome to CIWeb!</h1> <p>22 free HTML lessons. Start learning now.</p> </body> </html>
Welcome to CIWeb!
22 free HTML lessons. Start learning now.
What Each Part Does
Indentation: Professional vs Amateur
<!-- Amateur: impossible to read, debug, or maintain --> <html><head><title>Page</title></head><body><h1>Hi</h1><p>Text</p></body></html> <!-- Professional: 2 spaces per level, one element per line --> <html> <head> <title>Page</title> </head> <body> <h1>Hi</h1> <p>Text</p> </body> </html>
Over 60% of web traffic is mobile. Without <meta name="viewport"...> your page zooms out on phones making text tiny and unreadable. This one line is the difference between a page that works on mobile and one that doesn't.
Press F12 on any website to see its HTML structure. This is how real developers study how popular sites like Zomato, Swiggy, or Flipkart are built. Try it right now — open Google and press F12.
Before HTML5 there were 3 different versions and browsers rendered pages differently. DOCTYPE told them which rules to follow. HTML5 in 2014 simplified everything to just <!DOCTYPE html>. Short and done.