Document structure & meta tags
5 min lesson
- A well-formed HTML document has a fixed skeleton: doctype, html, head and body.
- The head holds information about the page, called metadata, which is not shown in the body.
- A meta tag describes the page; <meta charset="UTF-8"> tells the browser how to read characters.
- <meta name="viewport" content="width=device-width, initial-scale=1"> makes pages fit phone screens.
- <title> sets the text in the browser tab and in search results.
- This builds on Setup & your first page, where you saw a small skeleton, and prepares you for Linking CSS & JavaScript, which also lives in the head.
- The example adds a description and viewport meta; you will see the tab title and a correctly sized page.
- Every page needs doctype, html, head and body in that order.
- Put metadata in head; put visible content in body.
- Always set charset and viewport; they prevent garbled text and tiny phone layouts.
- Keep the head short and purposeful.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Tell the browser to read text as UTF-8 -->
<meta charset="UTF-8">
<!-- Make the page fit phone screens -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- A short description for search engines -->
<meta name="description" content="A tiny page about meta tags.">
<!-- The text shown in the browser tab -->
<title>Document structure</title>
</head>
<body>
<!-- The main heading the user sees -->
<h1>Structure matters</h1>
<!-- One short paragraph of visible text -->
<p>This page has a proper head and body.</p>
</body>
</html>What happens: A browser tab titled "Document structure" and a page showing the heading "Structure matters" and the paragraph "This page has a proper head and body."
Breaking it down
charset meta
<meta charset="UTF-8">Tells the browser which character encoding to use. Without it, accented letters and symbols may appear garbled.
viewport meta
<meta name="viewport" content="width=device-width, initial-scale=1">Tells phones to use their real width. Without it, pages look zoomed out and tiny on mobile.
description meta
<meta name="description" content="...">Gives search engines a short summary. It does not change the page look but can appear in search results.
title
<title>Document structure</title>Sets the tab text and the clickable headline in search results. Without it, the tab shows the file name.
Common head tags
| Tag | Purpose |
|---|---|
| <meta charset> | Sets the character encoding |
| <meta viewport> | Fits the page to the screen |
| <meta description> | Summarizes the page for search |
| <title> | Sets the browser tab text |
| <link> | Connects an external file like CSS |
A helpful analogy
The document is like a person: the head holds the brain (information about the page), and the body holds what everyone sees. Meta tags are like an ID card that describes the person to others.
Nesting rules
- 1.Keep meta and title inside head, never inside body.
- 2.Put charset first in head so the browser reads the rest correctly.
Common mistakes
Forgetting the viewport meta
Avoid
<meta charset="UTF-8"> onlyUse instead
<meta name="viewport" content="width=device-width, initial-scale=1">Without it, phones render the page as a wide desktop layout and shrink it, making text hard to read.
Putting title in the body
Avoid
<body><title>Hi</title></body>Use instead
<head><title>Hi</title></head>The title belongs in head. In the body it may not work and breaks the document structure.
Quick tips
- •Keep meta tags short; they describe the page, they do not fill it.
- •Check the tab text after each change; it is the quickest sign your title works.