Sub topic 2
Where metadata lives: the HTML head
This chapter covers the HTML <head> element, where the title, meta description, and canonical link are declared. It assumes you know basic HTML structure (head and body), what URLs and query strings are, and what HTTP status codes mean. You should also have seen a search results page.
What the head is for
An HTML document has two main parts. The <body> holds content that people see. The <head> holds information about the document. Browsers read the head to learn the character encoding, the tab title, linked stylesheets, and scripts. Search engines read it to learn how to index and display the page.
Three elements in the head matter most for this tutorial:
<title>is the page title. Search engines often use it as the clickable headline in results.<meta name="description">is a short summary. Search engines may use it as the snippet under the headline.<link rel="canonical">names the preferred URL when several URLs show the same content.
The title is an element with text inside it. The description and canonical are void elements. They have no closing tag, and their values sit in attributes.
A minimal, correct head
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trail Running Shoes for Beginners | Example Store</title>
<meta name="description" content="Compare cushioned trail running shoes for first-time runners, with fit tips and a size guide.">
<link rel="canonical" href="https://www.example.com/shoes/trail-running">
</head>
<body>
<h1>Trail Running Shoes for Beginners</h1>
</body>
</html>Read it from top to bottom:
<!DOCTYPE html>puts the browser in standards mode.lang="en"declares the page language. Search engines and screen readers both use it.<meta charset="utf-8">sets the character encoding. It should appear early, because the browser must know the encoding before it decodes text further down. The HTML specification requires it to fall within the first 1024 bytes of the document.- The title, description, and canonical all describe the same page. The title and the
<h1>agree on the topic. The canonical URL is absolute.
How a crawler reads the head
A crawler fetches the HTML, parses it, and extracts signals. The head is parsed first, so these tags are among the earliest things it sees.
The diagram below shows the order of events, from request to display.
Note the word "hint" for each signal. Search engines treat all three as suggestions. They compare them with the page content and other signals before deciding what to index and display. Later chapters explain when they override your values.
What belongs in the head, and what does not
Search engines recognize a limited set of head elements. Others exist for browsers or for social sharing.
| Element | Purpose | Used by search engines? |
|---|---|---|
| `<title>` | Page title | Yes, strongly |
| `<meta name="description">` | Summary text | Sometimes, for snippets |
| `<link rel="canonical">` | Preferred URL | Yes, as a hint |
| `<meta name="robots">` | Indexing directives such as `noindex` | Yes |
| `<meta name="viewport">` | Mobile layout | Yes, for mobile rendering |
| `<meta name="keywords">` | Keyword list | No. Google ignores it |
| `<meta property="og:title">` | Open Graph title for social previews | Not for ranking |
The keywords meta tag is a common leftover from old guides. You can remove it without any search impact.
Rules that decide whether the head is read correctly
The head is parsed by an HTML parser with specific rules. Several mistakes silently break metadata.
Keep body-only elements out of the head
When the parser meets an element that is not allowed in the head, such as <div> or <img>, it ends the head and starts the body. Every tag after that point is treated as body content. Search engines may then ignore a canonical link or description placed after the break.
<head>
<title>Example</title>
<div></div>
<link rel="canonical" href="https://www.example.com/page">
</head>In this example the <div> closes the head early. The canonical link ends up in the body. Google states that it ignores a rel="canonical" link outside the head. Keep scripts and tracking snippets that inject elements from running before your metadata tags, or load them after.
Use one of each
A page should have one <title>, one meta description, and one canonical link. If there are several, the engine has to choose, and you cannot control the choice. Duplicates usually come from a template and a plugin both adding tags.
Use real values, not placeholders
Empty or templated values such as <title>{{title}}</title> do appear in production when a variable is undefined. Check the rendered HTML, not just the template.
Server HTML versus rendered HTML
There are two versions of a page's head:
- The raw HTML the server sends.
- The rendered DOM after JavaScript runs.
If JavaScript changes the title or canonical after load, the crawler must render the page to see the change. Google does render JavaScript, but rendering happens later and can fail or be skipped. A mismatch also creates conflicting signals, for example a raw canonical that points to one URL and a rendered canonical that points to another.
The safest approach is to put final values in the server-sent HTML. If you must set them with JavaScript, set them consistently and test the rendered result.
Metadata outside the head
Some metadata does not live in the HTML head at all.
- HTTP headers. A
Linkresponse header can carry a canonical URL. This is the only option for files without a head, such as PDFs. TheX-Robots-Tagheader can carry robots directives. - Sitemaps. An XML sitemap lists URLs you want indexed. It supports the canonical idea indirectly, because you should list only canonical URLs.
HTTP/1.1 200 OK
Content-Type: application/pdf
Link: <https://www.example.com/guides/size-guide>; rel="canonical"Later chapters cover both in detail. For now, remember that the head is the usual home for metadata, not the only one.
Inspecting a head
Check what a crawler would see in these ways:
- Use "View page source" in a browser. This shows the raw HTML from the server.
- Use "Inspect" in developer tools. This shows the DOM after JavaScript.
- Run
curl -s https://www.example.com/pageand read the head. This shows raw HTML with no JavaScript. - Use the URL Inspection tool in Google Search Console to see the HTML Google rendered.
Compare the first two. Any difference in title, description, or canonical is a risk.
Common errors
- A
<div>,<img>, or iframe in the head ends it early, so later tags land in the body. - Two titles or two canonicals appear because a plugin and a theme both add them.
- The
<title>is empty, or shows a template placeholder. - The canonical
hrefis relative or contains a typo, so it points to a URL that does not exist. - The raw HTML and the rendered DOM disagree.
Exercise
A page's source has this head: <head><title>Boots</title><img src="logo.png"><link rel="canonical" href="https://www.example.com/boots"></head>. Why might a search engine ignore the canonical, and how do you fix it?
Show answer
The <img> element is not allowed in the head, so the parser closes the head when it reaches it. The canonical link is then parsed as part of the body, and Google ignores canonical links outside the head. Remove the <img> from the head (put it in the body), or move the canonical link above it.
Exercise
You view a page's source and see <title>Shop</title>, but the browser tab shows "Blue Boots | Shop". Which version will a crawler that does not run JavaScript see, and what should you change?
Show answer
It will see "Shop", because that is the title in the server-sent HTML. JavaScript changes the title after load. Change the server or template so it sends "Blue Boots | Shop" in the initial HTML.