HTML Page Structure
DOCTYPE, html, head, body — the required bones
Skills taught: html.document-structure, html.metadata
Every valid HTML document follows a required structure. Whether you're building a personal blog or a web application used by millions, the outer skeleton is always the same.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="A page about HTML structure" />
<title>Page Title</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Everything visible goes here -->
<h1>Page Heading</h1>
<p>Page content...</p>
<script src="app.js"></script>
</body>
</html>
The DOCTYPE declaration
The <!DOCTYPE html> declaration must be the very first thing in any HTML file. It tells the browser this is an HTML5 document. Without it, browsers enter quirks mode — an old compatibility mode that renders pages differently.
Tip: Always put <!DOCTYPE html> on the first line. No exceptions. It takes one second and prevents a category of difficult bugs.
The <html> element
The <html> element is the root of the document — everything else is inside it. The lang attribute tells browsers and screen readers the language of the page.
<html lang="en"> <!-- English -->
<html lang="hi"> <!-- Hindi -->
<html lang="es"> <!-- Spanish -->
<html lang="ar"> <!-- Arabic (right-to-left) -->
The lang attribute improves accessibility for screen readers and helps search engines understand the page language. Always include it.
The <head> section
The <head> element contains metadata — information about the page, not content on the page. None of it is visible to the user directly.
<meta charset="UTF-8"> — character encoding (always include this; UTF-8 supports every language)<meta name="viewport"> — controls zoom and layout on mobile devices<title> — the tab title shown in the browser and in search results<meta name="description"> — the snippet shown in Google search results<link rel="stylesheet"> — connects a CSS file to the page<link rel="icon"> — the favicon shown in the browser tab
The viewport meta tag
Without the viewport tag, mobile browsers zoom out to show the full desktop layout, making text tiny. This tag is essential for responsive design:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
The <body> section
The <body> element contains everything the user sees. Headings, paragraphs, images, forms, buttons — all of it goes inside <body>.
Tip: Place <script> tags at the end of the body, just before </body>. This allows the HTML to render before the script runs, making the page feel faster.
head vs body
- <head>: Invisible metadata about the page
- <body>: Everything the user sees
Frequently Asked Questions
What happens if I omit the DOCTYPE?
The browser enters 'quirks mode' — a legacy rendering mode that mimics old browsers (IE5, Netscape 4). Your layout will behave inconsistently across browsers. Always include it.
Can I have multiple <body> elements?
No. A valid HTML document has exactly one <html>, one <head>, and one <body>. Browsers may try to correct extra elements, but the behavior is undefined.
Why does the title tag matter for SEO?
The <title> is the blue clickable headline in Google search results. It's one of the most important SEO signals. Keep it under 60 characters and make it descriptive.