# The HTML Document Skeleton

> The fixed five-line frame every web page starts from: a doctype, an html root, and a head and body inside it.

Subject: HTML | Lesson 1 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/document-skeleton
Next: [The Head: charset, viewport, title](https://codewithanimation.in/html/the-head-essentials.md)

## What it is

Every HTML page begins from the same small frame. A `<!DOCTYPE html>` line at the very top, an `<html>` root element that wraps everything, and inside it two children: a `<head>` and a `<body>`. That is the skeleton, and every page you ever build lives inside it.

The split between `<head>` and `<body>` is the whole idea. The `<head>` is the setup the reader never sees, and the `<body>` is the content they do. Once that frame is in place, the rest of HTML is just filling in the body.

## Why it matters

This is the first thing you type on any page, so getting it right is the foundation everything else rests on. When the frame is correct, the browser reads your page in standards mode and your HTML behaves the way the modern rules say it should.

It also gives you the mental model the whole language hangs on: invisible setup in the head, visible content in the body. Almost every beginner bug about something not showing up, or showing up in the wrong place, comes back to mixing those two up.

## How it works

`<!DOCTYPE html>` comes first, before anything else. It is not really a tag and it has no closing tag; it is a short instruction that tells the browser to use the current HTML standard. It looks like a leftover from history because it is one, but you always include it.

Next is `<html lang="en">`, the root element that contains the entire page. The `lang` attribute names the page's language, which helps screen readers pronounce text correctly and helps browsers offer translation.

Inside `<html>` the `<head>` always comes before the `<body>`. The `<head>` holds metadata such as `<meta charset="utf-8">` and the `<title>`, none of which is drawn on the page. The `<body>` then holds everything the visitor actually sees, from headings and paragraphs to images and buttons.

## Common mistake: Skipping the doctype drops you into quirks mode

If you forget `<!DOCTYPE html>`, the browser does not error. It quietly switches to quirks mode, an old compatibility behaviour where some box sizes and spacing follow the buggy rules of the 1990s. Your layout then looks subtly wrong for reasons that are hard to trace. The fix is simply to keep that first line on every page.

## Tip: Type the skeleton first, every time

Start each new file with the full five-line frame before you write any content, and set `lang` on `<html>` and `<meta charset="utf-8">` in the head straight away so accents and emoji render and screen readers behave from the first keystroke. Most editors will scaffold the whole skeleton for you: in VS Code, type `!` then press Tab.

## Try it: See the structure

The same five-line skeleton, assembled piece by piece. Notice how the `<head>` stays invisible setup while only the `<body>` shows up on the page.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/document-skeleton

## Check yourself

### Question 1

What does <!DOCTYPE html> actually do?

- A. Tells the browser to use modern standards mode
- B. Imports the page's CSS file
- C. Sets the text shown in the browser tab

Correct answer: A

`<!DOCTYPE html>` is a historical artifact kept for one reason: it opts the page into standards mode so the browser follows the current HTML rules instead of old quirks-mode behaviour.

- Why not B: The doctype loads nothing. Styles are linked separately in the head.
- Why not C: That is the job of the `<title>` element, which lives in the head.

### Question 2

Where does the content a visitor can see belong?

- A. Inside <body>
- B. Inside <head>
- C. Directly inside <html>, between head and body

Correct answer: A

The `<body>` holds everything the visitor sees. The `<head>` is invisible setup. Keeping that split straight prevents most early HTML confusion.

- Why not B: The head is metadata only. Nothing inside it is drawn on the page.
- Why not C: `<html>` only holds the head and the body; visible content goes in the body.

### Question 3

In what order do <head> and <body> go inside <html>?

- A. <head> first, then <body>
- B. <body> first, then <head>
- C. Either order works

Correct answer: A

Inside `<html>` the `<head>` always comes before the `<body>`. The browser reads the setup in the head first, then renders the visible body.

- Why not B: The browser reads the head first to set the page up before drawing the body.
- Why not C: The order is fixed: the head must come before the body.

## Remember this

- Every page starts with `<!DOCTYPE html>`, then `<html>`, holding `<head>` then `<body>`.
- `<!DOCTYPE html>` opts into standards mode; leave it out and the browser falls back to quirks mode.
- The `<head>` holds metadata the user never sees; the `<body>` holds everything visible.
- Set `lang` on `<html>` and `<meta charset="utf-8">` in the head from the very start.
