1<!DOCTYPE html>2<html lang="en">3 <head>4 <meta charset="utf-8">5 <title>My page</title>6 </head>7 <body>8 <h1>Hello!</h1>9 </body>10</html>index.htmlNew tabMy pageHello!<html lang="en"><head><meta charset><title><body><h1><html><head><meta><title><body><h1>My pageHello!
Left: the HTML file, a complete page in ten linesFront right: the tree, html holding head and body, each holding its elementsChips: each tag travelling from its line to its boxLeft: index.html, a complete page in ten lines. Back right: a web browser with a tab, an address bar and a page. Front right: the page's tree, built as boxes inside boxes. As the browser reads each line, its tag hops to its box: html is the slab everything sits on, head and body are the two trays on it, and meta, title and h1 are chips in the trays. Only the title reaches the tab, and only what is in the body reaches the page. Then the levels lift apart to show parents and children, and the optional tags fade. The browser reads the whole file and builds the tree almost at once. The figure builds one part per step so you can follow it.

The outline

  1. Every complete HTML page has the same shape: a doctype line, then an html element that holds two parts, head and body. Here is a full page in ten lines. The indents show which part sits inside which.

Head: about the page

Body: the page itself

A tree of boxes

What happens

;; step 1/10 · same-shape
file     index.html   (plain text, 10 lines)
   1  <!DOCTYPE html>
   2  <html lang="en">
   3    <head>
   4      <meta charset="utf-8">
   5      <title>My page</title>
   6    </head>
   7    <body>
   8      <h1>Hello!</h1>
   9    </body>
  10  </html>
shape    doctype, then html = head + body

Indenting is only for people. The browser ignores the spaces at the start of a line, so the page looks the same without them; the indents just make the nesting easy to see. The browser reads the whole file and builds the tree almost at once. The figure builds one part per step so you can follow it.