Lesson 5 of 51 · Module 1, lesson 5 of 6 · 5 min

The HTML page skeleton

Understand every line of the standard HTML page, and the difference between the head and the body.

What you'll learn

  • What each line of the standard HTML page does
  • The difference between the head and the body
  • What elements, tags and attributes are

Why this matters

Every HTML page you ever write starts with the same few lines. This is the skeleton of the page. If you understand it, you can start any page from memory. If a line is missing, the page may still look fine on your computer and then show strange characters on someone else's, or look tiny on a phone.

Three words first

Look at this line:

html
<p>This is my first web page.</p>
  • A tag is a word in angle brackets. <p> is an opening tag. </p> is a closing tag: the same word with a slash /.
  • An element is the opening tag, the content, and the closing tag together. This whole line is one paragraph element.
  • Some elements have no content and no closing tag. <meta charset="UTF-8"> is one of them.

An attribute is extra information inside an opening tag. It has a name, an equals sign, and a value in quotes: lang="en". The lesson Attributes covers them in detail.

The skeleton

This is the page you made in the last lesson:

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>About me</title>
</head>
<body>
  <h1>Hello, I am learning HTML</h1>
  <p>This is my first web page.</p>
</body>
</html>

What each part does

LineWhat it does
<!DOCTYPE html>Tells the browser: "this is a modern HTML page". It must be the very first line. It is not a tag and has no closing part.
<html lang="en"> … </html>The root element. Everything else goes inside it. lang="en" says the page is in English. Screen readers use it to choose the right voice and pronunciation. For a page in another language, use that language's code, such as lang="es" for Spanish or lang="ar" for Arabic.
<head> … </head>Information about the page, for the browser. None of it appears on the page itself — except the title, on the tab.
<meta charset="UTF-8">Tells the browser which character encoding the file uses: the system that turns the saved file into letters. UTF-8 covers every alphabet and symbol, from é and ñ to Chinese, Arabic and emoji. Without this line, some letters can appear as strange symbols such as é.
<meta name="viewport" …>Tells phones to show the page at its real size. Without it, a phone shows a tiny, zoomed-out version of the page.
<title> … </title>The text on the browser tab, in bookmarks and in search results. Every page needs one.
<body> … </body>Everything the visitor sees: headings, paragraphs, images, links.

The skeleton code with the head section highlighted in yellow and the body section highlighted in blue. The head holds information for the browser and is not shown on the page, except the title, which appears on the tab. The body holds everything the visitor sees. A small browser shows the title "Tomato soup" on the tab and the heading and paragraph on the page.

Elements inside elements

Look at the shape of the skeleton again. <head> and <body> are inside <html>. <title> is inside <head>. <h1> and <p> are inside <body>. Putting elements inside other elements is called nesting.

The spaces at the start of lines (the indentation) show the nesting: each element that is inside another is moved in by two spaces. The browser ignores these spaces. They are there so that you can see the shape of the page at a glance.

One rule matters: close elements in the reverse order you opened them. <body> opened after <html>, so </body> closes before </html>.

What you'll see

The same page as in the previous lesson: the title About me on the tab, a heading and a paragraph. The skeleton itself is invisible — that is its job.

A shortcut in VS Code

In an empty .html file in VS Code, type ! and press Tab (or Enter). VS Code writes a skeleton for you. Two things to change every time: the <title> says Document — replace it with a real title — and check that lang matches the language of your page.

Type the skeleton by hand a few times first, until you know it. Then use the shortcut.

Try it yourself

Make a second page in your my-website folder:

  1. Create a new file called recipe.html.
  2. Write the full skeleton.
  3. Give it the title My favourite recipe.
  4. In the body, add an <h1> with the name of a dish and one <p> that describes it.
  5. Save, then open recipe.html in your browser from the my-website folder.

You should see your title on the tab, and your heading and paragraph on the page.

Common mistakes

  • Visible text inside <head>. The browser cannot show text in the head, so it quietly moves it into the body — often above your heading, where you did not expect it. Fix: everything the visitor should see goes inside <body>.
  • No <title>. The tab shows the file name, such as index.html, instead of a real title. Fix: add a <title> inside <head>.
  • Forgetting <meta charset="UTF-8">. Letters such as é, ü or ç may turn into symbols like é. Fix: make it the first line inside <head>.
  • Closing in the wrong order, such as </html> before </body>. Browsers often guess what you meant, so the page may look fine — but other tools will report an error. Fix: close the last element you opened first.
  • Two <body> elements. A page has exactly one head and one body.

Check yourself

  1. Which part of the skeleton holds everything the visitor sees?
  2. What does lang="en" tell the browser and screen readers?
  3. What problem can a missing <meta charset="UTF-8"> cause?

Answers

  1. The <body> element.
  2. That the page is written in English.
  3. Some letters, such as é, may appear as strange symbols.

Next: you can now write a complete page. The last lesson in this module shows you how to look inside any web page — including your own — with the browser's developer tools.

Chat with us on WhatsApp