# Anchor links in Confluence storage format

URL: https://goingstellar.ro/reference/confluence-storage-format/anchor-links/

An anchor link is an ac:link with an ac:anchor attribute, with or without a ri:page. On the same page it renders as an a href starting with a hash. The ADF form is an ordinary link mark with an href of the hash plus the anchor name.

## Storage format

```xml
<ac:link ac:anchor="anchor">
<ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body>
</ac:link>
<ac:link ac:anchor="anchor"><ri:page ri:content-title="pagetitle" /><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link>
```

## In the editor

- Insert the anchor macro from the toolbar or by typing a slash and the macro name, then link to it. Per the Atlassian documentation.

## As ADF (Confluence Cloud)

The ADF that Confluence Cloud builds for:

```xml
<p><ac:link ac:anchor="anchor"><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>
```

```json
{
 "type": "doc",
 "content": [
  {
   "type": "paragraph",
   "content": [
    {
     "text": "Anchor Link",
     "type": "text",
     "marks": [
      {
       "type": "link",
       "attrs": {
        "href": "#anchor"
       }
      }
     ]
    }
   ]
  }
 ],
 "version": 1
}
```

## Examples

Storage format sent:

```xml
<p><ac:link ac:anchor="anchor"><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>
```

A link to an anchor on the same page, the first anchor example in the documentation.

Rendered view (HTML):

```html
<p><a href="#anchor">Anchor Link</a></p>
```

Storage format after the round trip through ADF:

```xml
<p><ac:link ac:anchor="anchor"><ac:link-body>Anchor Link</ac:link-body></ac:link></p>
```

Sent to Confluence Cloud on 29 Nov 2026.

Storage format sent:

```xml
<p><ac:link ac:anchor="anchor"><ri:page ri:content-title="pagetitle"/><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>
```

A link to an anchor on another page, where the target page does not exist.

Rendered view (HTML):

```html
<p><a class="createlink" href="/wiki/pages/createpage.action?spaceKey=SD&amp;title=pagetitle&amp;linkCreation=true&amp;fromPageId=<page id>">Anchor Link</a></p>
```

Storage format after the round trip through ADF:

```xml
<p><ac:link><ri:page ri:content-title="pagetitle" /><ac:link-body>Anchor Link</ac:link-body></ac:link></p>
```

Sent to Confluence Cloud on 29 Nov 2026.

Storage format sent:

```xml
<p><a href="#section-two">same-page hash link</a></p>
```

A plain a href with only a hash, written without any ac: element.

Rendered view (HTML):

```html
<p><a href="#section-two" rel="nofollow">same-page hash link</a></p>
```

Storage format after the round trip through ADF:

```xml
<p><ac:link ac:anchor="section-two"><ac:link-body>same-page hash link</ac:link-body></ac:link></p>
```

Sent to Confluence Cloud on 29 Nov 2026.

## What changes in conversion

- A same-page anchor link becomes an ADF link mark with the href set to the hash and the anchor name. Storage comes back as an ac:link with ac:anchor and an ac:link-body.
- The body changes from a plain-text-link-body CDATA to a link-body. The text is the same, but the CDATA wrapper is gone.
- A plain a href with only a hash is converted into an ac:link with ac:anchor, so a hand-written hash link returns in the ac:link form.
- For an anchor link on another page, the ac:anchor attribute is not kept. The result links to the page and the anchor is gone.
- The anchor link with an image body could not be saved back as ADF in this test, since the save was refused with a conflict error.

## Pitfalls

- An anchor link to a page that is not found is displayed as a create page link, so the anchor part is never reached.
- The view keeps the anchor name as written. A name with a space produced an href of a hash followed by the name with the space, which is not a clean address.
- The anchor macro is invisible to the reader, so nothing on the page shows whether the name a link uses exists.

## Related

- [anchor macro](https://goingstellar.ro/reference/confluence-storage-format/anchor-macro/)
- [<ac:link> to a page](https://goingstellar.ro/reference/confluence-storage-format/page-links/)
- [Link bodies: plain text and rich](https://goingstellar.ro/reference/confluence-storage-format/link-bodies/)
- [<a href> external links](https://goingstellar.ro/reference/confluence-storage-format/external-links/)
- [<h1> to <h6> headings](https://goingstellar.ro/reference/confluence-storage-format/headings/)

## Sources

- [Confluence storage format (Atlassian Documentation)](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html)
- [Insert the anchor link macro (Atlassian Support)](https://support.atlassian.com/confluence-cloud/docs/insert-the-anchor-macro/)
- [Atlassian Document Format: document structure (Atlassian Developer)](https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/)

