Does Google Index My # Anchor Links?

by Ruud Hein March 26th, 2012 

named-anchor-links

Updated: John Mueller pointed out how HTML5 can be used for AJAX driven sites. See below.

Summary: yes, Google indexes on-page anchors and their on-that-same-page content but no Google doesn't by itself index content that would additionally be retrieved besides what's already on the page.

And no Google essentially doesn't index anchor links.

Anchors — also called named anchors — are places in a page or document you want to be able to directly link and jump to.

Anchor Links are clickable hyperlinks that lead directly to a named anchor. You can recognize them; at the end of the URL they have a pound/hash sign (#) followed by a name or number (called a fragment identifier. Like so: http://www.w3.org/TR/html401/intro/intro.html#fragment-uri

How Do I Make Named Anchors?

  1. By putting an <a name> link in your page:
    • <a name="section-name"></a>
    • <h1><a name="section-name">My Section</a></h1>
  2. By using an ID attribute for an element on your page:
    • <h1 id="section-name">My Section</h1>
    • <div id="section-name">My Section</div>

    In both cases the name needs to be unique.

    Does Google Index Named Anchors?

    Trick question. Google indexes complete web pages, not parts of web pages. So once it has indexed your page that contains named anchors, it has also automatically indexed your named anchors.

    Since 2009 Google at its own discretion may show a named anchor under a search result snippet if the named anchor is relevant to the search. To have that happen the page should also have some sort of table of content linking to the named anchors.

    No.

    Why not?

    When you click an anchor link your browsers asks the website for the whole document at the URL you just clicked minus everything starting from #:

    • you click: example.com/index.html#explain-this
    • your browsers asks for: example.com/index.html
    • once the server has sent this page your browser will then jump to that specific point in the page

    In other words: the browser never send the part after the # to the server and the server never knows about it.

    The automated "browser" that Google uses acts just like that and asks for the URL without the #

    No.

    If a page pulls in and shows different content depending on the # named anchor links clicked, Google does not see and index that content.

    Why not?

    In the above setup:

    • your browser asks for the complete document from the URL up until the # named anchor
    • it receives this document together with some JavaScript
    • when your browser jumps to the # part of the page the JavaScript is trigger and it — from inside your browser — asks the server to send over another piece of content
    • when the new content arrives your browser and the JavaScript piece everything together and make it look like one page

    For most practical purposes you can start from the idea that Googlebot (and other search crawlers) do not execute JavaScript. So because of the way browsers work (see above) Google's crawler cannot asks for the URL including the #: anchors in URLs never leave the browser, are never sent to the server, and if they were the server would have no idea what to do with them.

    In short: the web simply doesn't work like that.

    How Can I Make Dynamic AJAX Anchor Links Crawlable?

    Also in 2009 Google proposed a way to make AJAX content crawlable and indexable.

    The proposal relies on a 3 step process:

    1. Change your dynamic AJAX anchor links from #whatever to #!whatever <— notice the exclamation mark!
    2. When Google finds a link on the web that goes #!… Google will rewrite that part of the URL to ?_escaped_fragment_= followed by whatever was after your #
    3. It will then request this URL from your server

    Example:

    • Googlebot finds the link example.com/index.html#!explain
    • Google rewrites the URL to example.com/index.html?_escaped_fragment_=explain
    • Google adds that URL to its crawl list and will ask your server for that URL

    Updated: John Mueller points out that HTML5's pushState() makes it possible to build AJAX driven sites using good old-fashioned, regular links.

    Conclusion

    • Google indexes web pages; if those pages contain named anchors they will (also) be found and indexed too
    • If the page contains both named anchors and links on that page to those named anchors, Google may show one or more of those named anchors under a search result snippet if they think it is relevant for the query
    • Google does not index AJAX-powered dynamic content that is accessed via a named anchor URL
    • To make dynamic AJAX-powered URLs available for Google to be indexed they need to:
      1. be written as #! instead of just #
      2. be available on your server at the location ?_escaped_fragment_?=

        OR

      3. use regular links with HTML5's pushState() instead
    Ruud Hein

    My paid passion at Search Engine People sees me applying my passions and knowledge to a wide array of problems, ones I usually experience as challenges. People who know me know I love coffee.

    Ruud Hein

    You May Also Like

    Comments are closed.