Skip to the indexed answers
Digital Marketing Index

usdigitalmarketingindex.com SEO

Why are crawlable HTML anchor links preferable to click-handler-only navigation?

Because an anchor with an href states its destination in the markup, where a crawler, a browser, and assistive technology can all read it without running or triggering anything. A click handler on a div, span, or button states nothing. Its destination exists only inside a script that runs when someone clicks, and crawlers do not click. Google’s documentation is direct: it can discover links only if they are anchor elements with an href attribute (Google’s JavaScript SEO basics). Its separate guidance on links covers the markup and the anchor text in detail (Google’s guidance on crawlable links). The same markup that makes a link discoverable also makes it usable from a keyboard and openable in a new tab.

HTML anchor semantics

An anchor element with an href is the web’s definition of a link. It carries three things in plain markup.

  • A destination, in the href.
  • A label, in the text between the tags.
  • A role that every client understands as navigation.

Browsers build behavior on that: the status bar shows the address, a right click offers to open or copy it, a middle click opens a new tab, the Tab key reaches it, and Enter activates it. None of that exists for an element that merely has a click handler.

How crawler URL extraction works

The same JavaScript documentation describes link discovery as parsing: Googlebot “parses the response for other URLs in the href attribute of HTML links and adds the URLs to the crawl queue”, and after rendering it parses the rendered HTML for links again.

The crawler reads the document and collects href values. It does not press elements to find out where they lead. So:

Markup Does parsing find a URL?
Anchor with a real path in href Yes
Anchor with href and a click handler that intercepts it Yes; the href is still there
Anchor with no href No
Anchor with href set to a script or to a bare hash No usable URL
Div, span, or button with a click handler No

The second row matters for applications. Intercepting the click to change views without a reload is compatible with crawlable links, provided the href holds the real destination.

Bad and good markup

Before, a product card built from a div:

<div class="card" onclick="window.location.href='/products/trail-runner'">
  <img src="/images/trail-runner.jpg" alt="Trail Runner shoe">
  <span class="name">Trail Runner</span>
</div>

Problems: the document contains no href, so there is nothing to extract. The Tab key skips the card. A screen reader announces an image and some text with no indication that they lead anywhere. The visitor cannot open the product in a new tab.

Variants with the same fault:

<a onclick="goTo('/products/trail-runner')">Trail Runner</a>
<a href="javascript:goTo('/products/trail-runner')">Trail Runner</a>
<a href="#" onclick="goTo('/products/trail-runner')">Trail Runner</a>
<button onclick="goTo('/products/trail-runner')">Trail Runner</button>

After, the same card as a real link:

<a class="card" href="/products/trail-runner">
  <img src="/images/trail-runner.jpg" alt="">
  <span class="name">Trail Runner shoe</span>
</a>

The destination is in the href. The whole card is one link with a text label. The image’s alt is empty because the visible name already labels the link.

If the application needs to handle the navigation itself, keep the anchor and intercept it:

<a class="card" href="/products/trail-runner" data-route>Trail Runner shoe</a>

<script>
  document.addEventListener('click', function (event) {
    const link = event.target.closest('a[data-route]');
    if (!link || event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0) {
      return;
    }
    event.preventDefault();
    history.pushState({}, '', link.getAttribute('href'));
    renderRoute(link.getAttribute('href'));
  });
</script>

The handler steps aside for modified clicks, so opening in a new tab still works. The function renderRoute stands for the application’s own router.

A button remains the right element for actions that do not navigate: submitting a form, opening a dialog, adding to a cart. The rule is about destinations. If activating the control takes the user to another URL, it is a link.

Accessible navigation tests

The tests for crawlability and for accessibility largely coincide.

Test How Pass condition
Keyboard reach Press Tab through the page Every navigational control receives focus, in a sensible order
Keyboard activation Press Enter on a focused link It navigates
Visible focus Watch while tabbing The focused link is clearly indicated
New tab Middle click or use the context menu The destination opens in a new tab
Status bar Hover The browser shows the destination URL
Screen reader List the links on the page Each navigational control appears as a link with a meaningful name
Scripts disabled Disable JavaScript and click Links still navigate
Markup Search rendered HTML for navigational elements without href None found
Crawl Crawl with a tool, and compare with the routes you know exist Every route is discovered
Google's view URL Inspection live test, rendered HTML Links appear as anchors with real paths

Two of these can be run in a minute on any page: Tab through it, and hover over each control. A control that cannot be focused or shows no address is not a link.

Audit the components where this goes wrong: cards, table rows made clickable, tabs, pagination controls, breadcrumbs, logo links, and menus built from list items with handlers.

How a single-page application should structure its routes so that each view has an address for these links to point at is covered in the guide to how client-side routing can prevent crawlers from discovering distinct page URLs.

The rule: if it goes somewhere, it is an anchor, and the somewhere is in the href.

Link trail

Reader comments on this answer

Add your comment to this answer

Your email address will not be published. Required fields are marked *