squirrelscan
GitHub

Broken anchor links: #fragments that point at nothing

A link to #pricing whose target id is gone still loads, and the reader lands at the top of the page. squirrel checks every in-page anchor against the element it names.

An anchor link is an <a href> whose fragment names an element on the page: #pricing, or /docs/setup#install for a section of another page. The browser scrolls to the element with that id. If no element has the id any more, nothing errors. The page loads and the reader lands at the top, not at the section they clicked.

Anchors break after a redesign, a CMS migration, or a table of contents copied from another page. Headings get new generated ids, and the old links keep pointing at the old ones.

What squirrel checks

The rule is site-wide. It judges a link when the target page was crawled and answered without an error. A page’s id set is the id attributes and <a name> values on it, the two targets the HTML spec resolves a fragment to.

  • Skipped when there is no site data. Message: Site data not available for in-page anchor analysis.
  • Skipped, not passed, when the crawl’s page records were cached before this check existed and carry no anchor data. Message: In-page anchors were not checked: this crawl's page records predate the check. Re-run the audit with --refresh to check them.
  • broken-anchors warns when a link’s fragment names no id on its target page. Message: {count} in-page anchor link(s) point at an id that does not exist on the target page. Each item names the link and lists every page that links to it, so a broken anchor in the site navigation is one finding, not one per page. Severity warning, weight 4.
  • A broken skip link is labelled (skip link) in its item. The skip link is reported here, once. a11y/skip-link keeps its own verdict.
  • unconfirmed-anchors reports info for a link whose target id squirrel cannot confirm is missing, because the target page was fetched without rendering and its JavaScript may add the id after load. That is the case when the page looks like an empty client-side shell, or when the id appears anywhere on the page as a quoted string in an inline script (el.id = "size", setAttribute("id", "size"), <h2 id="size"> inside a string). Message: {count} in-page anchor link(s) target a page that was not rendered and may add the id with JavaScript.
  • broken-anchors passes otherwise. Message: No broken in-page anchor links detected, with details.anchorLinks (how many links the rule judged).

Matching follows the browser. The fragment is percent-decoded, so #caf%C3%A9 finds id="café", and the comparison is case-sensitive, so #Pricing does not match id="pricing".

What squirrel does not report

  • href="#" and #top. Both scroll to the top of the page by specification, whether or not an element has the id.
  • Purely numeric fragments such as #0 and #1. Templates use them as do-nothing links for menus and buttons that scripts drive, far more often than as ids, so a missing #0 is not reported.
  • Hash routes and state, which are not element ids: fragments starting with / or ! (#/settings, #!/home), and fragments containing = (#access_token=abc, #q=shoes).
  • Text fragments (#:~:text=hello).
  • Links to pages the crawl did not fetch, to other websites, or to pages that answered with a 4xx or 5xx. links/broken-links already reports the last two.
  • Targets with more than 512 distinct ids. A link into such a page could name an id that was not kept, so it is not judged.

Which audits can find a broken anchor

A same-page link needs only the page it sits on. A link into another page is checked only when that page was fetched. Surface and Full audit levels follow links, so they reach most targets. Quick, and the Sitemap crawl strategy, fetch the entry URL and the sitemap URLs only. A link into a page they did not fetch is not judged.

Pages that are built in the browser can add their ids after load. squirrel reports those as unconfirmed rather than broken, unless the page was rendered during the audit. A rendered audit reads the initialized DOM, so an id created at init passes and an id nothing created still fails.

The check is deliberately narrow, so a script on the page does not turn every missing id into an unconfirmed one. Only a missing id that an inline script names is unconfirmed; the other missing ids on the same page stay in broken-anchors. The match is a name match, not a creation test: the id counts when it appears anywhere as a quoted string of up to 64 characters in an inline script, so a generic fragment such as #contact can be unconfirmed because an analytics snippet mentions "contact". An id a script builds by concatenation ("size-" + n), or that an external script file creates, is not named in the page’s HTML, so an unrendered audit still reports it as broken. Audit with rendering on to check those. Scripts of a data type (application/ld+json, import maps, templates) are not read.

Reading is bounded: up to 256 KB of inline script text and 1,024 distinct quoted strings per page. Truncation never demotes anything. Text and strings past those limits are simply not read, so an id that only a later string names is reported as broken, the same as before this check existed.

When the page’s links carry a link section (see Page Classifier), each item says where the links to it sit and carries the counts in meta.sections, for example https://example.com/guide#gone, linked in the page content and the footer. Same-page #fragment links have no section, so their items stay as they were, and so does a crawl whose links carry none. Each item lists every page once, with sources saying how many of that page’s links point at the fragment (same-page links included) and where they sit; see source pages. Each item also counts the pages per section (regions), so a broken anchor in the site navigation of most pages is reported once for the navigation; see findings in a shared page region.

How to fix it

Update the link to the id that exists now, or add the id to the target element. Prefer fixing the link: an id added only to satisfy a link often breaks again in the next redesign.

Skip links need a target too. Give <main> or the content container the id the skip link points at, such as id="main-content".

Fix the source, not just the page. The report lists which pages carry each link, and a link repeated in the navigation needs one change rather than twenty.

Rule IDlinks/broken-anchors
CategoryReliability
ScopeSite-wide
Severitywarning
Weight4/10

Category and score

A link to #section whose target is gone lands the reader at the top of the page instead of where the link promised. That is the same failure as a broken link, so this rule is in the Reliability category even though its id keeps the links/ prefix, like links/broken-links and links/broken-external-links. The report badges it Reliability, and its findings count toward the Performance score group, the group Reliability rolls up into, instead of SEO. The overall health score weights every rule the same wherever it sits.

Because the id is unchanged, nothing you configured breaks. links/* in enable or disable still selects this rule, links/broken-anchors still names it in rule_options, and the docs URL is the same. reliability/* does not select it, because a pattern matches on the id, but --rule-include reliability and --rule-exclude reliability do name it. A JSON or published report written before this change still shows the rule under Links. An audit stored on your machine is rendered with the current categories when you run squirrel report, so it now shows the rule under Reliability.

Enable / disable

Disable this rule

[rules]
disable = ["links/broken-anchors"]
[rules]
disable = ["links/*"]

This rule is in the Reliability category but keeps its links/ id, so links/* selects it and reliability/* does not.

Enable only this rule

[rules]
enable = ["links/broken-anchors"]

enable replaces the default ["*"], so this is the only rule selected. Leave disable out: a rule that matches any disable pattern is skipped even when enable names it. Only an enabled setting under a rule’s own [rule_options] table overrides both lists.

Reliability findings ship in every audit next to the SEO, performance and agent experience rules. See Fix SEO issues with AI for how an agent works through a report.

Glossary: Broken link, Fragment link.

References

Check your website

Run squirrel audit https://example.com and open the Reliability section of the report. Each broken anchor is listed with the link and the pages that carry it. Signed-out local audits need no account and cost nothing. Signed-in audits spend credits.

Type to search…

↑↓ navigate↵ openesc close