What are anchor links?
Anchor links (also called anchor links, jump links and left section) are internal links to other sites on the same page. In other words, if a user clicks on an anchor link, they will be not led to a new page, but led to a place further down or up on the same page.
Anchor links are typically placed in a table of contents at the top of the page, allowing users to jump directly to relevant content, or in conjunction with a "To Top" button, allowing users to jump to the top of the page.
Anchor links serve two purposes: they improve usability by making it easier for users to move around the content on the page without scrolling, and they boost your presence on Google by - if you're lucky - showing the anchor links in search results. Anchor links appear either below the page's Meta Description or at the beginning of the page as a "Jump to" link:
We recommend that you include anchor links on content-heavy pages, where the links can help clarify the content and enhance the usability of the page. Anchor links should not be used on pages with little content - otherwise the links have no value for the user and Google will not show them.
Use of anchor links
An anchor link consists of two parts: an actual link and a unique ID associated with the element on the page being linked to. For example, the link might look like this: <a href="/en/”/#unikt-id”">Link text</a>. The hashtag (#) indicates that it is a link to an element on the same page.
The element being linked to must be assigned a unique ID using the code snippet id="unique-id". For example, the ID can be associated subheadings (<h2 id="”unikt-id”">Subheading</h2>) or sections of text (<p id="”unikt-id”">Text...</p>). Note that not hashtag (#) must precede ids.
Two elements on the same page may not have the same ID, but an ID may be reused across the website. Use hyphens instead of spaces in IDs, and avoid using capital letters and special characters. IDs can be contextual words or consecutive numbers, for example:
- https://inboundcph.dk/viden/hvad-er-seo#linkbuilding
- https://inboundcph.dk/viden/hvad-er-seo#3
The advantage of contextual words over numbers is that all identifiers do not have to be redrawn if a new section is added later in the middle of the page. For your work with SEO the ID is secondary. However, it is important to have a short, descriptive link text, as it is the link text that Google displays in the search results.
Note that the ID is at the end of the URL with a prefixed hashtag. For links to an id on the same page, it is sufficient to write only the id in the link (with a prefixed hashtag). For links to an id on another page, the whole URL should be written in the link.
Troubleshooting
Review the following three points if the anchor links are not working as intended.
- Check the ID. Check that the ID is unique, i.e. that it is not associated with several different elements in the page source code. Check that the id is correctly specified in both the link and the element - the former with a prefixed hashtag. Remember that there is a distinction between upper and lower case letters.
- Disable AJAX. The AJAX web technology used on some websites may affect the functionality of the anchor links. Disable AJAX on the anchor links to solve the problem. This can be done for example by adding the code snippet data-ajax="false" to the links.
- Check the header. On websites with a fixed header (a header that is constantly visible at the top of the window), the header may in some cases cover the top of the element being linked to (for example, a headline). This can be solved in several ways and requires consultation with your web developers.