Sub topic 11
Choosing descriptive anchor text
This chapter assumes you can write an a element with an href, and that you know internal links let search engines discover pages. It covers anchor text: the visible, clickable words of a link. Crawlable markup comes before this chapter, and anchor mistakes and link attributes come after it.
Why anchor text matters
Search engines read anchor text as a short description of the page being linked to. Readers use it the same way. Screen reader users often move through a list of links without the surrounding text, so each link has to make sense alone.
A page that receives many internal links with clear anchors gets a consistent signal about its topic. A page whose links all say "click here" gets no such signal.
Weak and strong anchors
Compare three ways to link to the same page.
<!-- Weak: generic anchor text -->
<a href="/guides/url-slugs/">click here</a>
<!-- Better: the anchor text describes the target page -->
<a href="/guides/url-slugs/">guide to writing URL slugs</a>
<!-- Not crawlable as a link: there is no a element with an href -->
<span onclick="location.href='/guides/url-slugs/'">guide to writing URL slugs</span>The first link is crawlable but says nothing about its target. The second is crawlable and descriptive. The third has good words, but search engines follow a elements with an href, so no link exists for them to follow.
A working test
Read the anchor aloud with nothing around it. Ask whether a stranger could guess where it leads. Three checks help:
- It describes the destination. "Internal linking checklist" tells the reader what they will get. "This page" does not.
- It is specific. "Slug guidelines" is better than "SEO tips" when the target covers only slugs.
- It reads naturally in the sentence. If you removed the link styling, the sentence should still read like normal prose.
Anchors do not have to match the target's title exactly. A link can say "how to choose a slug" while the target page is titled "Writing good slugs". Varying the wording is natural and is covered further in the next chapter.
Length and placement
Aim for roughly two to six words. A single word is often too vague. A full sentence makes the link hard to scan and blurs which words describe the target.
Put the link inside the body text, close to the idea it supports. Links in the main content tend to be more useful than a long list of unrelated links in a footer, because the surrounding sentence adds context.
<p>
Before you rename a page, read the
<a href="/guides/changing-slugs/">steps for changing a slug safely</a>
so that old links keep working.
</p>Finding generic anchors
A quick audit starts by listing every link's href and anchor text. This parser does that for one page, and you can then scan the output for phrases like "click here" or "read more".
from html.parser import HTMLParser
class LinkCollector(HTMLParser):
def __init__(self):
super().__init__()
self.links = []
self._href = None
self._text = []
def handle_starttag(self, tag, attrs):
if tag == "a":
self._href = dict(attrs).get("href")
self._text = []
def handle_data(self, data):
if self._href is not None:
self._text.append(data)
def handle_endtag(self, tag):
if tag == "a" and self._href is not None:
anchor = " ".join("".join(self._text).split())
self.links.append((self._href, anchor))
self._href = None
parser = LinkCollector()
parser.feed('<p>Read the <a href="/guides/url-slugs/">guide to URL slugs</a> or <a href="/more/">click here</a>.</p>')
print(parser.links) # [('/guides/url-slugs/', 'guide to URL slugs'), ('/more/', 'click here')]The output shows one descriptive anchor and one generic anchor pointing at /more/.
Common errors
- Using the same generic phrase ("read more") for many different targets.
- Linking whole sentences or paragraphs.
- Writing anchors for search engines in a way that no longer reads naturally.
- Using an image as the only link content without alt text, which leaves the link with no anchor text at all.
Exercise
A blog post says "For more details, click here." The link goes to /guides/changing-slugs/. Rewrite the sentence so the anchor text is descriptive, and name one reason it is better.
Show answer
For example: "For more details, read the steps for changing a slug safely." The anchor "steps for changing a slug safely" describes the target page, so search engines and screen reader users can tell where the link leads without reading the rest of the sentence.
Exercise
A link is written as <span onclick="location.href='/guides/url-slugs/'">guide to URL slugs</span>. Why does good anchor text not help here, and how do you fix it?
Show answer
There is no a element with an href, so search engines have no link to follow and do not read the words as anchor text. Replace the span with <a href="/guides/url-slugs/">guide to URL slugs</a>.