Sub topic 8
Controlling indexing with the robots meta tag
This chapter assumes you can write basic HTML, know the doctype/html/head/body structure, and have a rough idea of how a search engine crawls and indexes a page. The meta element, including its name and content attributes, was covered earlier in this tutorial.
What the robots meta tag does
The robots meta tag tells search engines how to treat the page it appears on. It uses the name and content attributes you already know:
<meta name="robots" content="noindex">This asks compliant search engines not to include the page in their search results. It is a request, not access control. Well-behaved crawlers such as Googlebot and Bingbot honor it. Other software can ignore it, and anyone with the URL can still open the page in a browser.
The common values
The content attribute holds one or more directives, separated by commas.
| Directive | Meaning |
|---|---|
| `index` | The page may be indexed. This is the default. |
| `noindex` | Do not show the page in search results. |
| `follow` | Links on the page may be followed. This is the default. |
| `nofollow` | Do not follow the links on the page. |
| `noarchive` | Do not offer a cached copy of the page. |
| `nosnippet` | Do not show a text snippet or preview for the page. |
Because index, follow is the default, you almost never write it. You add the tag only when you want to restrict something. Support for the less common directives varies between search engines, so check the documentation of the engines you care about.
You can combine directives:
<meta name="robots" content="noindex, nofollow">Targeting one crawler
Replace robots in the name attribute with a crawler's name to address only that crawler. Google documents googlebot for this purpose:
<meta name="googlebot" content="noindex">If a page has both a general and a specific tag, a crawler generally applies the most restrictive combination. Avoid relying on this. One clear tag is easier to reason about.
When to use noindex
Typical pages that should stay out of search results:
- Thank-you and order-confirmation pages.
- Internal search results pages.
- Staging or preview copies of a site.
- Printer-friendly duplicates of other pages.
Do not use it to protect private data. A page with noindex is still publicly reachable. Pages that must stay private need authentication on the server.
A common mistake: robots.txt blocking
A site can also have a robots.txt file that tells crawlers which URLs not to fetch. The two mechanisms interact in a way that surprises people. A crawler can only read the robots meta tag if it is allowed to fetch the page. If robots.txt blocks the URL, the crawler never sees your noindex. The URL can then still appear in search results, usually with no description, if other sites link to it.
To keep a page out of the index, leave it crawlable and put noindex on it.
Where it goes and how it is read
Place the tag anywhere inside head. Search engines read it from the HTML they receive, so a tag inserted by JavaScript may be seen later or not at all. Write it directly in the served HTML when you can.
Removal is not instant. After you add noindex, the page leaves the index only once the crawler visits it again. This can take days or weeks.
For files that are not HTML, such as PDFs, a meta tag is impossible. The equivalent is the X-Robots-Tag HTTP response header, which carries the same directives.
A worked example
This confirmation page should not appear in search results, but the link back to the shop is fine to follow.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<title>Order Confirmed - Example Store</title>
</head>
<body>
<h1>Thank you for your order</h1>
<p><a href="/shoes">Keep shopping</a></p>
</body>
</html>The robots tag sits with the other meta tags near the top of the head. Its order relative to them does not matter, but charset must still come first.
Exercise
A developer adds <meta name="robots" content="noindex"> to a page and also blocks that page's URL in robots.txt. Weeks later the URL still appears in search results. Why, and what should they change?
Show answer
The crawler is not allowed to fetch the page, so it never reads the noindex tag. Other sites linking to the URL can still cause it to be listed. The developer should remove the robots.txt block so the crawler can fetch the page and see noindex. After the next crawl, the page is dropped from the index.
Exercise
Is <meta name="robots" content="noindex"> a good way to hide a page of customer invoices from the public? Explain.
Show answer
No. The tag is only a request to compliant search engines. Anyone with the URL can still load the page. Invoices need server-side authentication.