HTML Internal Link: id, #anchor and Page Path Examples
November 11, 2026 · 10 min read
HTML Internal Link: Jump to Sections With id and #anchor
An HTML internal link points to a spot on the same page or to another page on the same site. For a same-page jump, give the target element an id and point <a href="#that-id"> at it. For another page, use a path such as /about/. The code below covers both cases, plus fixes for jumps that silently fail.
How to Make an HTML Internal Link to a Section
Every link in HTML is an <a> element with an href. The text between the tags is what the reader clicks. To jump within a page, you need two pieces: an id on the destination and a # plus that same value in the href.
<p><a href="#pricing">Jump to pricing</a></p>
<section>
<h2 id="pricing">Pricing</h2>
<p>Every plan includes unlimited projects.</p>
</section>
Clicking "Jump to pricing" scrolls the Pricing heading to the top of the window, as far as the page length allows. The address bar changes from page.html to page.html#pricing, and the Back button returns you to where you were. Nothing reloads, because the browser only scrolls.
That #pricing part of the URL is called the fragment. It's shareable too: open page.html#pricing in a new tab and the browser lands on the same heading.
Rules for id Values That Fragment Links Can Find
The HTML standard's id rules are short. An id must be unique in the document, contain at least one character, and contain no whitespace. Beyond that, HTML itself allows almost anything, including ids that start with a digit.
Browsers match the fragment against ids exactly, so case counts. A link to #Pricing won't find id="pricing". Any element can be a target, not only headings: a <section>, a <p>, a table row or a list item all work.
<!-- Breaks: space in the id, case mismatch -->
<h2 id="Pricing Plans">Pricing plans</h2>
<a href="#pricing-plans">See plans</a>
<!-- Works -->
<h2 id="pricing-plans">Pricing plans</h2>
<a href="#pricing-plans">See plans</a>
The first pair fails twice. The id holds a space, which isn't allowed, and its capital letters don't match the lowercase fragment. The second pair jumps as expected.
Non-English ids work too. The browser stores a link to #café in the URL as #caf%C3%A9, which is what you see when you copy it. Per the spec, the browser first looks for the raw fragment, then decodes it and tries again, so id="café" still matches.
We prefer lowercase words joined by hyphens, such as install-on-windows. They're readable in the URL, and they don't need escaping in CSS the way an id like 2026-notes does.
Two older habits also cause trouble. If an id appears twice, the browser jumps to the first one in the page, which may not be the one you meant. And <a name="pricing"> is the old way to mark a target. The spec lists it as obsolete and says authors shouldn't use it, so put an id on the real element instead.
How Do You Link Internal Pages in HTML?
In SEO talk, internal links are links between pages on the same site. In HTML they use the same <a href> markup as a section jump. The only difference is the value of href, which can be relative, root-relative or absolute.
Here's how each form resolves from a page at https://example.com/docs/guide/setup.html:
| href value | Type | Resolves to |
|---|---|---|
install.html | Relative | https://example.com/docs/guide/install.html |
../faq.html | Relative | https://example.com/docs/faq.html |
/blog/ | Root-relative | https://example.com/blog/ |
https://example.com/blog/ | Absolute | https://example.com/blog/ |
#step-2 | Fragment only | https://example.com/docs/guide/setup.html#step-2 |
A relative path starts from the current page's folder, and ../ climbs one folder up. A root-relative path starts with / and always begins at the domain root. An absolute URL names the full address. Our guide to folder structure for a website shows how each path style resolves from inside a subfolder.
<nav>
<a href="/">Home</a>
<a href="/docs/">Docs</a>
<a href="/blog/">Blog</a>
</nav>
For site navigation, we prefer root-relative paths like these. The same menu works on every page at any folder depth, and it keeps working when you move a page. Absolute URLs to your own domain send testers back to the live site when you preview on a staging domain.
One trap: a <base href> tag in the page's head changes how every relative URL resolves, including # links. With a base set to another address, href="#faq" sends the reader to that address instead of scrolling.
Linking to a Section on Another Page With page.html#id
You can combine a path and a fragment in one internal hyperlink in HTML. The browser loads the page, then scrolls to the matching id.
<a href="/docs/install.html#requirements">Check the requirements</a>
<a href="../faq.html#billing">Billing questions</a>
The first link opens the install page and lands on the element with id="requirements". The second climbs one folder, opens the FAQ and lands on id="billing".
This works across sites too, as long as the other page has that id. If the id doesn't exist, the page simply opens at the top with no error. That silent failure is why renamed headings break old links so often. When you change an id that other pages point to, search your site for the old fragment and update it.
Internal vs External Links: What Is the Difference?
An internal link points to a page on your own domain. An external link points to a different domain. Internal HTML links and external ones use identical markup, and an absolute URL to your own site still counts as internal.
In practice, the differences are small. Internal links normally open in the same tab, so readers can use the Back button. Settings such as target="_blank" are usually reserved for external pages, if you use them at all. The HTML anchor tag guide covers new tabs and rel values.
For search engines, the format matters more than the destination. Google's crawlable links guidance says Google can generally only crawl a link that's an <a> element with an href. A <span> or <button> that navigates through a click handler isn't a link Google can reliably follow.
<!-- Crawlable -->
<a href="/pricing/">Pricing</a>
<!-- Not reliably crawlable -->
<span onclick="location.href='/pricing/'">Pricing</span>
Back to Top Links, Skip Links and a Clickable Table of Contents
Three internal link patterns show up on almost every long page. Each one is plain HTML.
A back-to-top link needs no target at all. Under the HTML spec, the fragment #top scrolls to the top of the document when no element has that id. An empty # does the same, but #top says what it does.
<a href="#top">Back to top</a>
A skip link lets keyboard users jump past a long menu. It's the first technique (G1) listed for WCAG 2.4.1 Bypass Blocks, a Level A requirement.
<body>
<a class="skip-link" href="#main">Skip to main content</a>
<header>Site menu with many links</header>
<main id="main">Article starts here</main>
</body>
In most browsers, pressing Tab once on page load focuses the skip link, and Enter jumps to <main>. Safari skips links on Tab by default, so test there with Option+Tab. Many sites hide it visually until it receives focus, then slide it into view.
A table of contents is just a list of fragment links in a <nav>:
<nav aria-label="On this page">
<ol>
<li><a href="#install">Install</a></li>
<li><a href="#configure">Configure</a></li>
<li><a href="#deploy">Deploy</a></li>
</ol>
</nav>
Each item jumps to the section with the matching id. If you write in Markdown instead, our Markdown table of contents guide covers how platforms build them. The TOC generator builds a Markdown table of contents from your headings, with anchors in six platform slug styles including GitHub and GitLab.
Markdown's [Pricing](#pricing) compiles to the same <a href="#pricing">. Platforms generate heading ids differently, so read how Markdown heading ids work and our Markdown links guide before you rely on an auto-generated id.
Fixing Jump Links Hidden Under a Sticky Header
A fixed or sticky header covers the top of the window. When a jump lands, the target heading ends up hidden underneath it. The fix is one CSS property on the targets, scroll-margin-top.
h2[id], h3[id], section[id] {
scroll-margin-top: 5rem;
}
@media (prefers-reduced-motion: no-preference) {
html {
scroll-behavior: smooth;
}
}
:target {
background: #fff4c2;
}
The first rule leaves 5rem of space above each target when the browser scrolls it into view. Set it to your header's height plus a little breathing room. The CSS Scroll Snap spec tells browsers to use this margin for fragment navigation.
The second rule animates the jump instead of snapping, but only for people who haven't asked their system to reduce motion. The third rule uses :target, which matches the element whose id is in the URL fragment, to highlight the section you landed on.
How to Find Internal Links and Check They Work
To find the internal links on a page, open your browser's DevTools console and run this. It lists every link that stays on the current domain.
[...document.links]
.filter(a => a.hostname === location.hostname)
.map(a => a.href);
To catch fragment links that point at nothing, run this check. It skips # and #top, which scroll to the top without a target.
document.querySelectorAll('a[href^="#"]').forEach(a => {
const id = decodeURIComponent(a.getAttribute('href').slice(1));
if (id && id.toLowerCase() !== 'top' && !document.getElementById(id)) {
console.warn('No target for', a.getAttribute('href'));
}
});
Duplicate ids are just as easy to spot:
const counts = {};
document.querySelectorAll('[id]').forEach(el => {
counts[el.id] = (counts[el.id] || 0) + 1;
});
console.log(Object.keys(counts).filter(id => counts[id] > 1));
These checks have a clear limit. They test one page as it looks right now. They don't follow links to other pages, and they miss ids that JavaScript adds later. For a whole site, run a link crawler to catch broken jumps. Google Search Console's Links report also lists your most internally linked pages, though it doesn't flag broken ones.
There's one more limit to know if you draft in Markdown. Our editor's preview gives headings no id, so #section links won't jump there. Check your jumps in the published HTML page instead.
Quick Answers About HTML Jump Links
A working HTML internal link needs two things. One is an href with the right path or fragment, and the other is a unique, exact-match id at the far end. Add scroll-margin-top for sticky headers, a skip link for keyboard users, and run the console checks before you publish. If you draft pages in Markdown first, write them in the Markdown editor, then test every jump in the final HTML.