1 / 10 · Intro
What a web page is
Every page you open starts as a plain text file. Right-click almost any page, choose View Page Source, and you can read the HTML the server sent.
Jump to the 12 practice questionsYou will learn
- Picture the DOM tree the browser builds
1Explain
A page is a text file
A web page is a text file written in HTML that a browser reads and draws on screen. When you type an address into a browser, the browser asks a server for a file and gets back plain text. That text is written in HTML, the HyperText Markup Language. The browser reads it from top to bottom, works out which parts are headings, paragraphs, links and pictures, and then draws the page you see.
Change the words in the editor: the preview redraws the page the way a browser would.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Corner Bakery</title>
</head>
<body>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning from 7 am.</p>
</body>
</html>2Explain
Web, website, web page
These words are often mixed up. A web page is one document that a browser can display, written in HTML. A website is a collection of linked web pages that share one domain name, such as bakery.example. A web server is a computer that stores websites and sends their files to a browser that asks for them; one server can host many websites. The web is all of these pages and sites, linked together across the internet.
Definitions follow MDN Learn, “Browsing the web”.
3Problem
One site, three pages
The bakery has a home page, a menu page and a contact page, all at bakery.example. Which description is right?
Hint
Pages that share one domain name belong to one site.
Solution
Answer: 1 website with 3 web pages
Each HTML document is a web page; together, under bakery.example, they make one website.
4Problem
Sending or drawing
You open bakery.example/menu.html. Which one turns the HTML into the page you see?
Hint
One side sends the file, the other side reads it.
Solution
Answer: The browser
The web server only sends the file. The browser reads the HTML, builds the tree and draws the page.
5Explain
The skeleton, part by part
Inside <html> there are two parts. The <head> holds information about the page that is not drawn in the page itself. <meta charset="utf-8"> says which character encoding the file uses; UTF-8 can store the letters of every writing system, Korean included, so text will not turn into strange symbols. The <title> is the name shown on the browser tab, in bookmarks and in search results, and it is the first thing a screen reader announces when the page opens.
| Part | What it does |
|---|---|
| <!DOCTYPE html> | Tells the browser to use standards mode |
| <html lang="en"> | Wraps the whole page and names its language |
| <head> | Holds information about the page |
| <title> | Sets the name on the browser tab |
| <body> | Holds everything shown on screen |
6Problem
Where visible content goes
Where does content that appears on screen go?
Hint
One part of the page holds information about it; the other holds what is drawn.
Solution
Answer: body
Everything visible belongs in body. head holds information about the page.
7Explore
What goes in body
Only what is inside body is drawn. The title in head appears on the browser tab, not on the page.
Tap a choice: the code and the preview change together.
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>Corner Bakery</title></head>
<body>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>
</body>
</html>Nothing is drawn: there is no visible content.
8Problem
The name on the tab
Which element sets the name shown on the browser tab?
Hint
It sits in head and is not drawn on the page.
Solution
Answer: title
The title element, placed inside head, names the tab, bookmarks and search results.
9Explain
From text to a tree
The browser does not keep your HTML as one long string. The browser turns HTML into a family tree called the DOM, the Document Object Model. Each element is a point in the tree, called a node, and an element inside another becomes its child. In the figure below, title is a child of head, and h1 and p are children of body. CSS selectors and JavaScript both work on this tree, which is one reason careful nesting matters.
The DOM tree of the bakery page. Lines join each element to the element that contains it.
10Problem
What the DOM is
What is the DOM?
Hint
It is what the browser builds from your HTML.
Solution
Answer: The tree of objects built from the HTML
Each element becomes a node and nested elements become its children, which is how CSS and JavaScript pick out any part of the page.
11Problem
The parent of title
Hint
Which element contains title in the skeleton?
Solution
Answer: head
title is written inside head, so head is its parent in the tree.
12Problem
Nodes under body
<body>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>
<p>
<strong>Daily from 7 am.</strong>
</p>
</body>How many elements are inside body in this code? Count the nested ones too.
Hint
h1 and the two p elements are children of body; look inside the second p as well.
Solution
Answer: 4
h1, p, p and strong: 4 elements. strong is a child of the second p, so it is a grandchild of body.
13Practice
Finish the skeleton
Finish the skeleton: add lang="en" to <html>, a <title> that says Corner Bakery, an <h1> with the same words, and one paragraph.
- lang="en" on html
- title in head
- h1 heading
- a paragraph
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
</body>
</html>Hint
lang goes inside the html start tag; title goes in head; h1 and p go in body.
A solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Corner Bakery</title>
</head>
<body>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>
</body>
</html>14Explain
Common mistakes
Browsers are forgiving. If you forget a closing tag, the parser follows repair rules written into the HTML standard and still builds a tree, but the repaired tree may not be the one you meant. Getting into the habit of writing the structure correctly saves a lot of puzzled debugging later.
<p>Open <b>daily</p>
<p>from 7 am</b></p><p>Open <b>daily</b></p>
<p>from 7 am</p>The browser repairs the overlapping tags in its own way, and the bold leaks into the second paragraph. Close tags in the reverse order you opened them.
15
Summary
- A web page is a text file of HTML that the browser turns into a tree (the DOM).
- Skeleton: DOCTYPE, html with lang, head (meta charset, title), body.
- HTML labels meaning; CSS styles it; JavaScript adds behaviour.