Anatomy of an HTML Document
Take apart the small skeleton every page shares — doctype, language, head metadata and body — and see what each part does before a single style is applied.
Contentsand lesson path
On this page
- Why it matters
- The skeleton, line by line
- Metadata that earns its place
- From markup to DOM
- Check your understanding
- Apply it
- Review prompt
Lessons of Semantic HTML
- Anatomy of an HTML Document Concept · 15 min
- Headings, Landmarks and the Page Outline Worked example · 20 min
- Choosing Elements by Meaning, Not Looks Concept · 20 min
- Alternatives and Labels for Images, Media and Inputs Concept · 20 min
- Lab: Mark Up an Article Page and Inspect Its Accessibility Tree Lab · 30 min
- Check: Spot the Semantic Errors Knowledge check · 8 questions
What you will learn
- Structure a page with a correct document skeleton, metadata, a logical heading hierarchy and landmark elements (header, nav, main, footer).
01. Why it matters
Every page you will ever build rests on the same small skeleton: a doctype, an html element with a language, a head full of metadata and a body of content. It is tempting to treat that skeleton as boilerplate to paste without reading, but each part does real work. The character encoding decides how your bytes become text. The viewport setting decides how wide your layout is on a phone. The lang attribute decides how a screen reader pronounces every word on the page. The title is what a search engine shows before anyone has seen your design.
Browsers are forgiving. Feed them broken HTML and they will guess, repair and render something anyway. That forgiveness is a strength of the web — old pages still open — but it hides mistakes until some browser, crawler or assistive technology guesses differently from yours. Learning the skeleton is learning which decisions the browser is quietly making on your behalf, so that you can make them on purpose.
02. The skeleton, line by line
Here is a complete, valid HTML page. Everything else in this skill builds on these fourteen lines.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mooring notes: lines, fenders and knots</title>
<meta name="description"
content="A short guide to the lines and knots used when mooring.">
</head>
<body>
<h1>Mooring notes</h1>
<p>Which line goes where, and which knot holds.</p>
</body>
</html><!DOCTYPE html>is not an element; it is a flag. It tells the browser to lay the page out in standards mode, following the modern specification. Without it, the browser falls back to quirks mode, a compatibility behaviour that imitates the bugs of 1990s browsers: spacing around images changes, percentage heights behave differently and your CSS will not mean what you think it means.<html lang="en">names the human language of the content. Screen readers use it to pick a pronunciation voice and dictionary; translation tools use it to know which language they are translating from; browsers use it for hyphenation and quote marks. A page without a language is announced in the screen reader's default language.<head>holds metadata: things the browser reads but does not paint. Nothing in it is page content.<body>holds everything people see: text, images, forms, and the structure you will add in the next lesson.
title: Mooring notes: lines, fenders and knots
lang: en
head children: META, META, TITLE, META
meta: (charset) = utf-8
meta: viewport = width=device-width, initial-scale=1
meta: description = A short guide to the lines and knots used when mooring.
body children: H1, PA short parsing script reports what the browser-level document actually holds: the title as its own property, the language on the root element, four metadata elements in the head, and two content elements in the body. This tree is the real product of your markup. Styles, scripts and the accessibility tree are all built from it, which is why getting the skeleton right matters more than how the raw file looks.
03. Metadata that earns its place
The head is small on purpose. Four pieces of metadata belong on essentially every page.
charset="utf-8"says how the file's bytes map to characters. Declare it first, before any text the parser might read in another encoding; a page saved as UTF-8 but declared as something else showscaféwhere you wrotecafé. UTF-8 is the web's default encoding and the right choice for new files.- The viewport meta names the width the layout should assume. Without
width=device-width, a phone pretends the page is about 980 pixels wide and shrinks the result to fit, so your small-screen styles never apply and the text is unreadably small. With it, the layout width is the real device width andinitial-scale=1starts the zoom at 100%. <title>is the name of the document, not of a heading on it. It appears in the browser tab, in bookmarks, in history, and as the main line of a search result. Write one per page that would make sense in a list of tabs: specific, front-loaded, and free of "Welcome to".- The description meta is a fallback summary that search engines and messaging apps may show under your link. Keep it to a sentence or two that a person wrote.
A useful habit: after writing a page, read only its head and ask "if this were all a visitor saw, would they know what they were getting?" On the open web, that is often true — the title and description are the first two lines of your page anyone meets.
04. From markup to DOM
The browser does not keep your file; it reads the tags and builds a tree of objects called the DOM (Document Object Model). CSS selects nodes in that tree, scripts change it, and the accessibility tree that assistive technology reads is derived from it. When you "inspect a page", you are looking at its DOM, not your source file.
The parser repairs almost anything: a missing closing tag, a stray element in the head, text outside the body. It never shows an error page for HTML. This is why a page can look fine to you and still be wrong — the repair may have moved your elements somewhere you did not intend, or dropped them. The fix is not to trust your eyes but to check the rules, which you will do with a validator in the lab at the end of this skill. Validation is also the fourth objective of this skill: markup you have checked, not markup you hope is right.
05. Check your understanding
06. Apply it
Open the page source of a site you use often (right-click, then "View page source", not the inspector). Find the doctype, the lang attribute, the charset, the viewport meta, the title and the description. Note which of the six are missing or wrong — you will usually find at least one. Then write the skeleton from memory with the minimal document covered, and keep it as a template for the article page you will convert in the lab. When you later take the skill's practice task — converting a div-only news article into valid, named-up HTML — this template is its starting point.
07. Review prompt
Without looking back, write the skeleton of an HTML document from memory and say out loud what each head element does, what quirks mode is, and why a browser never reports an HTML syntax error to the person visiting the page.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.