šļø Foundation Building
HTML Document Structure
Learn how browsers read and render your HTML code, from raw bytes to beautiful web pages. Master the essential skeleton of every website.
How Browsers Read HTML
HTML Document Templates
Basic HTML5 Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Page</title>
</head>
<body>
<h1>Hello World!</h1>
<p>Welcome to my website.</p>
</body>
</html>Essential Document Elements
šÆ
<!DOCTYPE html>Document Type Declaration
Tells browser this is HTML5 document
Required
š³
<html>Root Element
Container for all HTML content
Required
š§
<head>Document Metadata
Contains page info, styles, scripts
Required
š¤
<meta charset>Character Encoding
Defines text encoding (UTF-8 recommended)
Essential
š±
<meta viewport>Responsive Design
Controls mobile viewport scaling
Mobile Essential
š·ļø
<title>Page Title
Shows in browser tab and search results
Required for SEO
š
<body>Content Container
Holds all visible page content
Required
š³ Visual DOM Tree Structure
How HTML becomes a Tree
Browsers parse your flat HTML into a hierarchical tree structure
HTML Source
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Hello</h1>
<div>
<p>World</p>
</div>
</body>
</html>DOM Tree Structure
document
āāā html
āāā head
ā āāā title "My Page"
āāā body
āāā h1 "Hello"
āāā div
āāā p "World"
šØ Common Structural Mistakes
What to Avoid
ā
Missing DOCTYPE declarationā
No viewport meta tag for mobileā
Incorrect character encodingā
Multiple <body> tagsā
Content outside <html> tagsā
Missing <title> elementā
No language attribute on <html>ā
Scripts blocking renderingBest Practices
ā
Always start with <!DOCTYPE html>ā
Include viewport meta tagā
Use UTF-8 character encodingā
Single <body> elementā
All content inside <html>ā
Descriptive <title> for SEOā
Specify lang attributeā
Use async/defer for scriptsš§© Build Your HTML Structure
Drag and drop the elements to build a proper HTML document structure
Available Elements
<!DOCTYPE html><html><head><meta charset><meta viewport><title><body>Your Document Structure
Drag elements here to build your HTML document
šÆ Key Takeaways
šļø
Solid Foundation
Proper HTML structure is the foundation of every website
ā”
Performance
Correct structure helps browsers render faster
š
SEO & Accessibility
Proper HTML improves search ranking and accessibility