HTML Document Structure
The DOCTYPE Declaration
<!DOCTYPE html> is the very first line of every HTML5 document. It's not an HTML tag — it's an instruction to the browser. It says: "Render this page in HTML5 standards mode."
<!DOCTYPE html> <!-- Always first, no exceptions -->
<!DOCTYPE HTML> and <!doctype html> both work — but uppercase is the convention.<!DOCTYPE html>.The <html> Root Element
The <html> element wraps the entire document. Every other element in the page is a descendant of this root. It has one critical attribute you should always include:
<html lang="en"> <!-- All head and body content goes here --> </html>
The lang attribute declares the primary language of the page. It's used by:
en (English), en-US (American English), fr (French), ar (Arabic), zh (Chinese), ur (Urdu). Omitting lang is an accessibility failure.The <head> — Invisible Metadata
The <head> contains information about the page — none of it is rendered directly on screen. Think of it as the document's control panel.
| Element | Purpose | Required? |
|---|---|---|
<meta charset="UTF-8"> | Character encoding — supports all Unicode characters | ✅ Yes |
<meta name="viewport"...> | Mobile responsiveness — critical for modern sites | ✅ Yes |
<title> | Browser tab text + SEO page title | ✅ Yes |
<meta name="description"> | Search engine snippet text (155 chars) | Recommended |
<link rel="stylesheet"> | Links to external CSS files | If using CSS |
<link rel="icon"> | Favicon — tab icon | Recommended |
<script> | JavaScript (prefer at end of body or with defer) | If using JS |
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Page Title — My Site Name</title> <meta name="description" content="A 155-char description of this page for search engines."> <link rel="icon" href="favicon.ico"> <link rel="stylesheet" href="css/style.css"> </head>
The <body> — Visible Content
The <body> contains everything the user sees and interacts with. Every visible element on your page — text, images, buttons, forms, navigation — lives inside the body.
<head> and one <body>. Browsers will often "fix" missing or duplicate elements, but the resulting DOM may be unpredictable. Always write the correct structure.<body> <header> <nav>...</nav> </header> <main> <h1>Page Heading</h1> <p>Content goes here.</p> </main> <footer>...</footer> <!-- Scripts go here (before closing body) --> <script src="js/main.js"></script> </body>
Comments in HTML
Comments let you leave notes in your code that browsers ignore. They're essential for documentation, debugging, and temporarily disabling code.
<!-- This is a single-line comment --> <!-- This is a multi-line comment --> <!-- TODO: Add the contact form here --> <div class="contact">...</div> <!-- <p>This paragraph is commented out (disabled)</p> -->
The Complete Document Skeleton
Here is the full template you should start every HTML project with. Every element here has a purpose — don't remove any of them:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title | Site Name</title> <meta name="description" content="Brief description of this page (max 155 chars)."> <link rel="icon" href="/favicon.ico"> <link rel="stylesheet" href="css/style.css"> </head> <body> <!-- Site header / navigation --> <header> <nav></nav> </header> <!-- Main page content --> <main> <h1>Your Page Heading</h1> </main> <!-- Footer --> <footer></footer> <!-- Scripts at end of body --> <script src="js/main.js"></script> </body> </html>
<!DOCTYPE html>?lang attribute on <html> important?Create 3 HTML files in a folder:
index.html, about.html, contact.html.Each file must have: correct DOCTYPE, html element with lang="en", complete head section (charset, viewport, unique title, meta description, link to style.css), body section with a header, main (with an h1), and footer. Add at least 2 HTML comments — one in the head, one in the body.
Also create an empty
css/style.css file and an empty js/main.js file. Your project structure should match the standard folder layout from section 6.
Show hints
- Each page title should be unique: "Home | MySite", "About | MySite", "Contact | MySite"
- The meta description should describe each specific page
- Create the css/ and js/ folders first, then the files inside them
- Open the project in VS Code: File → Open Folder