Sub topic 2
Where metadata lives: the HTML head
This chapter assumes you know the basic structure of an HTML document (a head and a body) and can read a URL with a query string. It introduces the part of the page that holds the title, the meta description, and the canonical URL.
Head and body do different jobs
An HTML document has two main parts. The body holds what visitors see. The head holds information about the page, called metadata. Browsers use some of it directly, such as the character encoding and the tab title. Search engines read the rest when they crawl the page.
Three head elements matter for this tutorial:
- The
titleelement names the page. - The
metaelement withname="description"summarizes the page. - The
linkelement withrel="canonical"names the preferred URL for the page's content.
<!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>All three elements describe the same page. The title and description should match what the body says, and the canonical URL should be the address of this content.
Rules that keep the head readable
Search engines parse the head quickly and expect it in a predictable form. Follow these rules:
- Put these elements inside
<head>. Atitleor canonicallinkin thebodymay be ignored. - Include one
title, one meta description, and one canonical link. Duplicates force the search engine to guess which one you meant. - Declare
<meta charset="utf-8">early, so special characters in titles and descriptions are read correctly. - Make sure the head is in the HTML the server returns, or at least in the rendered page. Search engines may not run your JavaScript at crawl time, so tags injected late can be missed.
Metadata is a hint, not a command
The head states what you want. The search engine decides what it does. It may show a different title than the one you wrote, build its own snippet from page text, or pick another canonical URL. Later chapters cover why and how to respond. For now, treat head tags as accurate, consistent input.
Checking what the server sends
To see the head a crawler receives, request the page without a browser:
curl -s https://www.example.com/shoes/trail-running | head -n 20Compare this output with "View Source" and with the inspected DOM. If a tag appears only in the DOM, a script added it, and a crawler might not see it.
Exercise
A developer adds the canonical link with JavaScript after the page loads. Two other pages in the same site have the tag in the server's HTML. Where would you look first to find out whether crawlers can see the tag on the first page, and what would you compare?
Show answer
Fetch the page with curl (or use View Source) and check whether the canonical link appears in the raw HTML. Then compare it with the inspected DOM in developer tools. If the tag appears only in the DOM, a script created it, and crawlers that don't run the script may miss it. The fix is to output the tag in the server-rendered head, as the other two pages do.