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 understand that a search engine crawls pages and stores some of them in an index. You should also know the general <meta name="..." content="..."> pattern from earlier in this tutorial.
What the robots meta tag does
A search engine works in stages. A crawler fetches a page, the engine decides whether to add it to its index, and later the index supplies results for searches. The robots meta tag gives you a say in the second stage and in how the result is displayed.
<meta name="robots" content="noindex">This asks compliant search engines not to include the page in their results. The tag lives in the head, uses name="robots", and carries one or more directives in content.
Three points define how far the tag reaches:
- It is a request. Major search engines honor it. Other crawlers, scrapers, and bots may ignore it.
- It is not access control. Anyone with the URL can still open the page. Use authentication for anything private.
- It acts only after the crawler fetches the page. The crawler must be able to read the HTML to see the tag.
Default behavior
If a page has no robots meta tag, search engines treat it as index, follow. You never need to write those values to get that behavior. Add the tag only when you want to change something.
| Directive | Effect |
|---|---|
| `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 this page. |
| `none` | Shorthand for `noindex, nofollow`. |
| `all` | Shorthand for `index, follow`. |
| `noarchive` | Do not offer a cached copy of the page. |
| `nosnippet` | Show no text snippet or video preview for the page. |
| `max-snippet:N` | Limit the text snippet to N characters. |
| `max-image-preview:SETTING` | Limit image preview size: `none`, `standard`, or `large`. |
| `unavailable_after:DATE` | Stop showing the page after a given date and time. |
Support varies by search engine. The directives above are documented by Google. Other engines support a smaller set, and the exact behavior of nofollow has changed over time, so treat it as a hint. Check each engine's documentation if a specific engine matters to you.
Writing directives
Separate directives with commas. Names are not case-sensitive, and extra spaces after commas are fine.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Order Confirmation - Example Store</title>
<meta name="robots" content="noindex, nofollow">
</head>
<body>
<h1>Thank you for your order</h1>
</body>
</html>An order confirmation page is a typical case. It is useful to the buyer, but it has no value as a search result.
You can also control how an indexed page appears, without removing it:
<meta name="robots" content="max-snippet:160, max-image-preview:large">This allows a snippet of up to 160 characters and a large image preview. The related meta description from the previous chapter suggests snippet text. These snippet directives set the upper limit on what the engine may show.
To remove a page automatically after an event, give a date with a time zone:
<meta name="robots" content="unavailable_after: 2027-01-31T23:59:59Z">Use a clearly formatted date such as ISO 8601. Google accepts several formats, but an unambiguous one avoids surprises.
Targeting one crawler
The value robots addresses all compliant crawlers. To address one, use its token as the name.
<meta name="robots" content="index, follow">
<meta name="googlebot" content="noindex">Here, Google's crawler is asked not to index the page, while other engines see the general rule. When a crawler-specific tag and the general tag conflict, search engines generally combine them and apply the more restrictive result. Avoid conflicting tags where you can, because they are hard to reason about. Use one tag unless you have a real reason to differ per engine.
How the crawler decides
The top branch in this diagram causes the most confusion, so the next section covers it.
Common mistake: robots.txt plus noindex
A robots.txt file controls crawling, which is fetching. The robots meta tag controls indexing, which is storing and showing. They are different tools, and mixing them up breaks things.
Suppose you add noindex to a page and also block that page in robots.txt:
User-agent: *
Disallow: /private-report/The crawler obeys robots.txt and never fetches /private-report/. It therefore never reads the noindex tag. If other sites link to that URL, the engine can still list the bare URL in results, usually without a snippet, because it knows the URL exists but cannot see your instruction.
To remove a page from results, let the crawler fetch it and serve noindex. Once the page has dropped out of the index, you can block crawling if you still want to.
Non-HTML files and the X-Robots-Tag header
A PDF or an image has no head, so a meta tag cannot go in it. For these files, the server sends the same directives as an HTTP response header named X-Robots-Tag.
location ~* \.pdf$ {
add_header X-Robots-Tag "noindex, noarchive";
}This nginx rule marks every PDF response as not to be indexed or cached. The header also works for HTML pages, and it is useful when you want one rule to cover a whole directory without editing each template.
The directive values and their meaning are the same as in the meta tag. If both the header and the meta tag are present, the engine considers both, and the more restrictive directive wins.
Placement and syntax details
- Put the tag in the
head. A robots meta tag in thebodyis invalid HTML, and crawlers may ignore it. - The tag must be in the HTML the crawler receives. If JavaScript inserts
noindexafter load, some crawlers will see it only after rendering, and some will not wait. Prefer putting it in the served HTML. - The opposite is also a trap. If your server HTML says
noindexand JavaScript later removes it, the crawler may act on the original value. Make the served HTML correct. - Use only the directives you need. An unrecognized value in the list is ignored by the engine, but a typo such as
noindxmeans your intended directive does not apply. - Do not set
noindexand arel="canonical"link pointing at a different page on the same document. The signals conflict. Canonical says "treat this as a copy of that page," while noindex says "drop this page." Choose one.
Effects take time
A noindex tag does not remove a page immediately. The engine must crawl the page again and read the new tag. Pages that are crawled rarely can stay in results for days or weeks. Search consoles offered by search engines typically provide a way to request a recrawl, or a temporary removal tool for urgent cases.
Choosing a method
| Goal | Use |
|---|---|
| Keep an HTML page out of results | `noindex` meta tag or `X-Robots-Tag` |
| Keep a PDF or image out of results | `X-Robots-Tag` header |
| Keep a page private | Authentication, not a robots tag |
| Reduce crawl load on unimportant URLs | `robots.txt` |
| Shorten or control snippets | `max-snippet`, `nosnippet` |
| Retire a page on a known date | `unavailable_after` |
Checking your work
- Open the page, then view the source (not the Elements panel) to see exactly what the server sent. Confirm the tag is inside
head. - In the browser developer tools, open the Network tab, select the document request, and read the response headers for
X-Robots-Tag. - In the Elements panel, search for
name="robots"to see what the page contains after JavaScript ran. Compare it with the source view. - Use the URL inspection feature of your search engine's webmaster tool to see whether the engine reports "noindex" for the page.
- Run the page through an HTML validator to catch a misplaced or malformed tag.
Exercise
A team adds <meta name="robots" content="noindex"> to /old-sale/ and also adds Disallow: /old-sale/ to robots.txt. Weeks later the URL still appears in search results, without a snippet. Why does this happen, and how do they fix it?
Show answer
The Disallow rule stops the crawler from fetching the page, so it never reads the noindex tag. Other sites that link to the URL keep it known to the engine, which lists the bare URL. To fix it, remove the Disallow rule so the crawler can fetch the page and see noindex. After the page leaves the index, they can block crawling again if they want to.
Exercise
You need to keep a downloadable file, whitepaper.pdf, out of search results. A meta tag is not possible for a PDF. What do you use, and what does it look like?
Show answer
Send an X-Robots-Tag HTTP response header with the noindex directive, for example X-Robots-Tag: noindex. In nginx, add_header X-Robots-Tag "noindex"; inside a location block that matches the PDF files does this.
Exercise
What does <meta name="robots" content="max-snippet:120, max-image-preview:large"> do, and does it remove the page from search results?
Show answer
It allows a text snippet of at most 120 characters and a large image preview in results. It does not remove the page. Without a noindex directive, the page can still be indexed.