How to link to an anchor on the page?
Asked by Shivansh Singh:

I have created an anchor on a page as follows

{anchor:here}

But I am unable to link to the above anchor. I am using Confluence 3.4.8. When I write the following markup in the rich text editor it displays the text as-is rather than showing it as a link to anchor.

\[#here\]

Am I missing something?


Answers:
author: NikolayS
body: I tried to repeat steps from Atlassian Achors tutorial, but confluence could not find my anchors (strange). [This video](https://www.youtube.com/watch?v=b7jpko_2-qE) helped me to make links to anchors work.

Briefly:

* create an anchor with name "anchorname"
* show "Insert link" popup -\> Advanced tag -\> in Link field enter "#anchorname" (without quotes). Save link, save draft.


author: pasquale.gagliano
body: I had a need to add a link to a paragraph in the same page; to do so I have added a Table of Content that has generated all the links to all headings in the page. Then where I needed to add the link I have simply added the link as per ToC


author: James Brown
body: I just wasted hours trying to do this. I added the anchor macro to the bottom of a page and gave it the name Bookmark.  
I navigated to another page in a different space and inserted a link using the advanced option. I entered IHopeThisWorks as the link text followed by spacekey:pagename#Bookmark (obiviously using the actual space key and page name and it did not work.  
Is there an issue when using special characters in a page name?

comments: author: BlueberryCake
body: I don't think there is an issue with special characters in this regard only. Just tried the following: Inserting an HTML link via code editor as \<a name="anchorname"\>xxx\</a\> and it won't work , too. The tags are deleted while being parsed, creating a blank output of "xxxx" I checked the code, there are no tags anymore an dlinking doesn't work. This means it wouldn't be possible to set alink to an achor from outside the system at all. \*sad\*

Never use capitals or special chracters in identifier's or variable's names.

I just discovered the following workaround:

> ### Link to a heading on a page {#toc-hId-1055754641}
>
> Choose **Link** \> **Advanced** then enter the heading in one of the formats below. Heading text is case sensitive and must be entered without spaces.

*
  > For a heading on this page: `#MyHeading`.

<https://confluence.atlassian.com/confcloud/insert-links-and-anchors-724764900.html>


author: BlueberryCake
body: But in order to answer your question: Never use special characters or capitals when naming variables or identifiers


author: BlueberryCake
body: Sorry for crossposting my own comments. Found a solution to link from outside. It's a little bit crude: Confluence uses the following syntax when it comes to anchor linking: <http://domain.com/display/SPACESHORTCUT/pagename#pagename-anchorname>


author: Jon Wilkins
body: I've also spent *hours* (if not days) trying to get linking to Confluence page anchors from external pages (including in some cases, ironically, Jira tickets) and the above info finally solved most cases for me.

However, I've figured out some nuances that are worth adding here to save others' time:

Using the basic structure above:

*<http://domain.com/display/SPACESHORTCUT/pagename#pagename-anchorname>*

1) Page titles with punctuation (specifically brackets "(" \& ")" but may include others:

The punctuation marks are  
- removed from the pagename in the URL *path* (left of the #)  
- retained in the pagename in the URL *fragment* (right of the #)

example

For a page title "This \& That" with anchor "001", the link would be

[http://domain.com/display/SPACESHORTCUT/This+That#This\&That-001](http://domain.com/display/SPACESHORTCUT/This+That#This&That-001)

2) Page titles that start with a number:

The pagename in the URL *fragment* seems to get prefixed with "id-"

e.g For a page title "1 Guide" with anchor "001", the link would be

<http://domain.com/display/SPACESHORTCUT/1+Guide#id-1Guide-001>


author: Danny Oliva
body: [@Jon Wilkins](/t5/user/viewprofilepage/user-id/293736)thanks Jon! your examples helped me out a TON!


author: Joe Clark
body: Firstly, as Kevin says, you can't type anchor links like that directly into the Rich Text editor using wiki markup syntax - you should either swap to the wiki markup editor, or use the "link browser" dialog in the Rich Text editor to type in the link.

Secondly, I'm fairly certain you need to include the page title in the link, in addition to the name of the anchor, so try:

```
[PageTitle#anchorName]
```

comments: author: Shivansh Singh
body: To link to an anchor I followed following steps: -

1. In the rich text editor edit mode, pressed Ctrl+K to open link browser.

2. Typed the page name. As I started typing the page name confluence automatically lists the page names which inlucde that keywork which I am typing.

3. After entering page name I added anchor name like this - Home#Overview

4. Saved the page.

When I click on the link, it navigates me to the top of the Home page and not the Overview segment of the page. I check the wiki markup of the page for the link and it is as follows:

\[Overview\|MySpace:Home\]

Above markup is in the form: -

\[\<Link text\>\|\<space name\>:\<Page title\>\]

It doesn't include the anchor name, even when I specified the anchor name at the time of specifying the link in the link browser. When I modify the above markup in the "wiki markup" view as below it works fine.

\[Overview\|MySpace:Home#Overview\]

So, it seems to me that there is some bug in Confluence. When we give anchor name from link browser it doesn't include it in the markup, but when I explicitly mention the anchor name in the "wiki markup" view, it works absolutely fine.


author: Kevin Buchs
body: I think this is beyond the scope of the rich text editor in Confluence versions \< 4.0. It is most reliably done in Wiki markup.


author: Shivansh Singh
body: Is it the problem with ver. \< 4.0? How about ver. 4.0 or greater?


author: Kevin Buchs
body: Everything related to such problems changes in 4.0 and such problems are excluded by design. It is a whole new editor.


author: Kevin Buchs
body: You cannot simply past the markup in the Rich Text editor. You need to select the "Insert Macro" tool bar button (looks like a little scroll), choose the Anchor macro and then enter your anchor label as the target, with # preceeding. Then I believe the best choice is to insert your hyperlink using the Link macro.

comments: author: Shivansh Singh
body: My anchor has been created properly because when I save page and see the view it doesn't shows the anchor tag.

But the problem is I am not able to link to the anchor I have created. When I write \[#here\], it displays the text as is with "#" symbol.


author: Kevin Buchs
body: Go ahead and paste the Wiki markup for your page here. We can probably explain it better that way.


Tags: anchor