Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Document Structure  ›  Lesson

head and body

head 12 minInside html sit exactly two children: head holds information about the page that is mostly not displayed, and body holds everything the visitor actually sees.

head and body

Think of a book. The cover, the barcode and the publishing details describe the book; the chapters are the book. An HTML document has the same split, and it is written into its structure as two elements: head and body.

The rule

head is about the page; body is the page.

The html element has exactly two children, always in this order:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Rainy Day Reads</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1>Rainy Day Reads</h1>
    <p>Five short books for a wet afternoon.</p>
  </body>
</html>

head holds metadata: information about the document. The character encoding, the title that appears in the browser tab, links to stylesheets, a description for search results and scripts all go here. Almost nothing in head is drawn on the page itself.

body holds the content: headings, paragraphs, images, links, lists, forms. If a visitor can see it, hear it or click it inside the page, it lives in body.

There is exactly one head and one body, and nothing sits between them or after body. Browsers will try to repair a document that breaks this rule, but, as you learned earlier, a repaired tree is a guessed tree.

The shortcut

For every item, ask: "Would it appear inside the page window?" Yes means body; no means head.

Sorting five itemsStep 1 of 5
  1. The tab text "Rainy Day Reads"

    It shows in the browser tab, not inside the page. So it is <title> in head.

The trap is the word "heading". head is not where headings go. A heading like <h1> is visible content and lives in body.

Why does this split matter in practice? Programs other than browsers read your page too. A search engine reads the head to learn the title and description. A chat app that shows a link preview reads the head to find a title and an image. None of them need to wade through the body to get that information, because it lives in a predictable place.

Drills

Answer fast — trust the rule.

quick drill

Where does the <title> element belong?

quick drill

Where should the main <h1> heading go?

quick drill

What is the correct order of children inside html?

quick drill

Which of these belongs in head?

Remember

  • head holds information about the page; body holds everything shown in the page window.
  • Shortcut: "would it appear inside the page window?" Yes means body, no means head.
  • Trap: head is not for headings; <h1> to <h6> go in body.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainSorting into head and body

You have these items: the page title shown in the browser tab, a link to a stylesheet, the main heading, a photo, and the character encoding. Say which belong in head and which in body, and state the rule you used.