# Add stable anchors

- Check 32.18 · Readability and direct answers · Important
- Source: https://checklist-seo-geo.com/en/readability-direct-answers/add-stable-anchors
- Give sections, tables and key answers a fixed identifier, keep it when the heading changes and check it with every release.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/readability-direct-answers/add-stable-anchors.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

An anchor is an `id` attribute placed on an element of the page, which lets you link directly to that passage: `https://example.com/tarifs/#entretien-chaudiere`. A stable anchor is one chosen by hand, readable, that no longer changes after it is published, even if the section heading is reworded. Once the task is done, every important section, table or answer has a precise, lasting address that internal links, shares and citations can target.

## Why it matters

An AI assistant or a search engine that cites a page points to a passage, not to a whole page. The more addressable that passage is, the more directly a reader who clicks lands on the answer. An anchor is also what your teams, your customers and other sites use to point to “the pricing section” or “the question about the warranty”.

Google documents the “Read more” links that lead to a specific section of a page in its snippets. Its best practices: make the content immediately visible (not hidden in tabs or expandable sections), do not force the scroll position with JavaScript on load, and do not remove the `#…` fragment from the URL with the History API or `window.location.hash`, which breaks deep links. Google can also scroll a page to a passage without any anchor on your part. Text fragment links (`#:~:text=`), supported by recent browsers, target a passage by its content: if that text is rewritten, they only lead to the top of the page.

A stable `id` anchor is the only marker you control. It does not break when you reword a sentence, provided it is not regenerated from the heading. Yet that is what many tools do: they derive the identifier from the heading text. Edit “2026 prices” into “2026 prices and lead times” and `#2026-prices` becomes `#2026-prices-and-lead-times`: every existing link leads to the top of the page.

Tables of contents and creating anchors on long content are covered in [add a table of contents and anchors to long content](https://checklist-seo-geo.com/en/page-seo-metadata/add-table-contents-anchors-long-content). This guide is about keeping them stable and about which elements to anchor for generative engines.

## What it improves

- **Links to a precise passage**: from your pages, your emails, support, other sites.
- **Citations in AI answers**: an addressable passage is easier to point to and to check. No practice guarantees a citation.
- **Robustness**: existing links survive rewrites and redesigns.
- **Accessibility and navigation**: a direct jump to the section, useful on mobile.
- **Rankings**: no direct effect. Google indexes the page under a single URL, without the fragment.

## How to check

**List the anchors on a page**:

```bash
curl -s https://example.com/tarifs/ | grep -o -E 'id="[^"]+"' | sort | uniq -c | sort -rn
```

A number greater than 1 at the start of a line means a duplicate identifier. Anchors such as `h-section-3`, `toc-2` or a random string mean a generated identifier.

**Compare two versions** to detect anchors that have disappeared, for example production and staging, or the page before and after a change:

```bash
diff <(curl -s https://example.com/tarifs/ | grep -o -E 'id="[^"]+"' | sort -u) \
     <(curl -s https://preprod.example.com/tarifs/ | grep -o -E 'id="[^"]+"' | sort -u)
```

Lines starting with `<` are anchors that are about to disappear.

**Check the fragment on load**: open `https://example.com/tarifs/#entretien-chaudiere` in a private window. The page must open on the section, and the address must keep the `#entretien-chaudiere`.

Expected result: sections, tables and key answers carry a readable, unique `id` that stays the same from one version to the next.

## How to implement

### Before you start

**What to anchor.** H2 headings and important H3 headings, but also the elements that answer a question on their own:

| Element | Example `id` |
|---|---|
| Pricing section | `tarifs` |
| Comparison table | `comparatif-formules` |
| FAQ question | `faq-garantie` |
| Definition | `definition-planning-preventif` |
| Step in a procedure | `etape-3-vidanger` |
| Part of a transcript | `importer-techniciens` |

**Naming rules**: lowercase, words separated by hyphens, no accents or spaces, three or four words at most, unique within the page, starting with a letter. Avoid years and sequence numbers (`tarifs-2026`, `section-4`), which go out of date or move.

**Stability rule**: once published, an anchor is treated like a URL. The heading can change; the `id` stays. If you really have to rename it, keep the old identifier on an empty element just before the section:

```html
<span id="tarifs-2026" aria-hidden="true"></span>
<h2 id="tarifs">Prices and call-out times</h2>
```

**What not to do in JavaScript**: clear the fragment from the URL on load, force a jump back to the top of the page, or only create the `id` attributes after a script has run. Put the identifiers in the served HTML.

**Shared CSS**, so that a sticky header does not hide the target:

```css
:target,
[id] {
  scroll-margin-top: 5rem;
}
```

### Check anchors with every release

Add the anchor comparison to your pre-release testing: a script that lists the `id` attributes of important pages in production, then in staging, and fails if an identifier disappears. The principle is the same as the `diff` command in the “How to check” section. During a redesign, the anchor inventory is one of the things to preserve: see [preserve structured data, entity identifiers and important anchors](https://checklist-seo-geo.com/en/redesign-migration/preserve-structured-data-entity-identifiers-important-anchors).

### WordPress

Versions: WordPress 6.5 and later, block editor.

Select the block (Heading, Table, Paragraph, Group…), then in the `Block > Advanced` panel, fill in the “HTML anchor” field. Enter the identifier without the `#`. It must be unique, start with a letter and contain no spaces; it is case-sensitive.

If a table of contents plugin generates anchors from the heading text, set by hand the anchors of the sections that other pages or citations target: the anchor entered in the “HTML anchor” field does not change when you edit the heading.

### Shopify

Versions: Shopify admin rich text editor, November 2026.

In a page or a blog post, click “Show HTML” in the rich text editor, then add the attribute to the element: `<h2 id="garantie">Warranty</h2>`. Save, and check in the published source code that the attribute has been kept. For the sections of an Online Store 2.0 theme, add an `anchor` text setting to the section schema and output it on the container:

```liquid
<section id="{{ section.settings.anchor | default: section.id }}">
  {{ section.settings.heading }}
</section>

{% schema %}
{
  "name": "Block with anchor",
  "settings": [
    { "type": "text", "id": "anchor", "label": "Anchor (without #)" },
    { "type": "text", "id": "heading", "label": "Heading" }
  ]
}
{% endschema %}
```

`section.id` is generated by Shopify and can change if the section is recreated: fill in the “Anchor” field for important sections.

### Drupal

Versions: Drupal 10 and 11, CKEditor 5.

In `Configuration > Content authoring > Text formats and editors`, edit the format you use, for example Full HTML. Add the “Source” button to the CKEditor 5 toolbar, then, in the Source editing settings, add `<h2 id> <h3 id>` to the Manually editable HTML tags field. Editors can then enter the `id` in the editor's source view.

### Webflow

Versions: Webflow Designer, November 2026.

Select the element, open the Element settings panel and fill in the ID field. In a collection Rich Text field, headings have no identifier you can set one by one: for pages that need to be cited precisely, use heading elements placed in the Designer, or an Embed element containing the HTML with its `id` attributes.

### Laravel

Versions: Laravel 11 to 13, league/commonmark 2.

`Str::markdown()` accepts League CommonMark extensions as its third argument. Combine the Attributes extension, to write a fixed `id` in the Markdown, with Heading Permalink, to give an `id` to the other headings:

```php
use Illuminate\Support\Str;
use League\CommonMark\Extension\Attributes\AttributesExtension;
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;

$html = Str::markdown($guide->body, [
    'heading_permalink' => [
        'apply_id_to_heading' => true,
        'id_prefix' => '',
        'fragment_prefix' => '',
        'insert' => 'none',
        'min_heading_level' => 2,
        'max_heading_level' => 3,
    ],
], [
    new AttributesExtension(),
    new HeadingPermalinkExtension(),
]);
```

In the Markdown, the fixed identifier is declared on the line before the heading:

```txt
{#tarifs}
## Prices and call-out times
```

With `apply_id_to_heading` set to `true`, the `id` declared through the Attributes extension replaces the one generated from the text. Headings without a declaration keep an `id` derived from their text, which will change if the heading changes.

### Next.js

Versions: Next.js 15 and 16 (App Router), @next/mdx.

The `rehype-slug` plugin adds an `id` derived from the text to headings that do not have one:

```js
// next.config.mjs
import createMDX from '@next/mdx'

const nextConfig = {
  pageExtensions: ['js', 'jsx', 'md', 'mdx', 'ts', 'tsx'],
}

const withMDX = createMDX({
  options: {
    rehypePlugins: ['rehype-slug'],
  },
})

export default withMDX(nextConfig)
```

The plugin name is passed as a string to stay compatible with Turbopack. For sections that must stay stable, write the heading in JSX in the MDX file: `<h2 id="tarifs">Prices and call-out times</h2>`. In React components, hard-code the `id`, never derive it from a loop index.

### Astro

Versions: Astro 5 and later.

Astro adds an `id` to every heading in Markdown and MDX files, derived from the text with `github-slugger`. It therefore changes if the heading changes. For a fixed anchor, write the heading in HTML in an `.mdx` file: `<h2 id="tarifs">Prices and call-out times</h2>`. In an `.astro` component, hard-code the `id`.

## Common mistakes

- **Anchors regenerated from the heading**: every edit breaks existing links.
- **Opaque or numbered identifiers** (`#section-3`, `#h-a1b2`): they shift as soon as a section is inserted.
- **A year in the anchor** (`#tarifs-2026`): it becomes wrong the following year.
- **Duplicates**: two `id="faq"` on the same page; the link goes to the first one.
- **Fragment cleared on load** by a routing or tracking script: deep links stop working.
- **Target content hidden** in a tab or a closed accordion: the link lands on a heading with no visible answer.
- **`id` attributes added with JavaScript after load**: missing from the served HTML.

## Frequently asked questions

### Does an HTML anchor improve SEO?

No, not directly. Google indexes a page under a single URL, without the fragment, and does not rank sections separately. A stable anchor is used to link to a precise passage: from your own pages, from other sites, in customer support or in a citation. It helps readers land on the answer and prevents existing links from breaking when content is rewritten.

### What happens if I change a section's heading?

If the anchor is generated automatically from the heading, it changes with it, and every link that targeted the old address leads to the top of the page. Set the identifier by hand for important sections and keep it when you reword the heading. If you really have to rename it, keep the old identifier on an empty element placed just before the section.

### What is the difference between an anchor and a text fragment link?

An anchor is an id attribute you place in the HTML: the #identifier link works as long as the id exists. A text fragment link, in the form #:~:text=, targets a passage by its content and requires no change to the page, but it stops working as soon as the targeted text is rewritten. The two complement each other: only the anchor is under your control.

### Should every FAQ question have an anchor?

Yes, it is useful if your FAQ questions are linked from other pages, shared by support or likely to be cited. Give each question a short, descriptive identifier, such as faq-garantie or faq-delai-livraison, rather than a number that changes when you reorder the list. Also check that the answer is visible when someone arrives through the link, not folded into a closed accordion.

## Resources

- [Google Search Central: “Read more” deep links in snippets](https://developers.google.com/search/docs/appearance/snippet?hl=en)
- [Google Search Central: URL structure best practices](https://developers.google.com/search/docs/crawling-indexing/url-structure?hl=en)
- [MDN: id attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/id)
- [MDN: Text fragments](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments)
- [WordPress: Page jumps and HTML anchors](https://wordpress.org/documentation/article/page-jumps/)
- [league/commonmark: Attributes extension](https://commonmark.thephpleague.com/2.x/extensions/attributes/) and [Heading Permalink](https://commonmark.thephpleague.com/2.x/extensions/heading-permalinks/)
- [Next.js: MDX and rehype plugins](https://nextjs.org/docs/app/guides/mdx)
- [Astro: heading IDs in Markdown](https://docs.astro.build/en/guides/markdown-content/)

Next steps: [Keep URLs stable](https://checklist-seo-geo.com/en/ai-agent-compatibility/keep-urls-stable) and [Give studies a stable URL](https://checklist-seo-geo.com/en/citability-original-data/give-studies-stable-url).
