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.
What Are 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?
- By putting an <a name> link in your page:
- <a name="section-name"></a>
- <h1><a name="section-name">My Section</a></h1>
- 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.
Does Google Index Anchor Links?
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 #
Does Google Index Dynamic AJAX Content With Anchor Links?
If a page pulls in and shows different content depending on the # named anchor links clicked, Google does not see and index that content.
In the above setup:
- your browser asks for the complete document from the URL up until the # named anchor
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:
- Change your dynamic AJAX anchor links from #whatever to #!whatever <— notice the exclamation mark!
- 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 #
- It will then request this URL from your server
- 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.
- 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:
- be written as #! instead of just #
- be available on your server at the location ?_escaped_fragment_?=
- use regular links with HTML5's pushState() instead