HTML Link Bookmarks
In this page:
Marking a Destination with id
Any HTML element can become a bookmark destination by giving it a unique id attribute -- this does not need to be a special anchor tag; a heading, a div, or a paragraph can all serve as a jump target as long as its id is unique on the page.
Note: Give major sections descriptive, readable ids (like id="pricing") instead of generic ones (like id="section3") for easier maintenance.
Warning: Every id value on a page must be unique; reusing the same id on two elements makes bookmark navigation behave unpredictably.
Example: Marking a Destination with id
<h2 id="pricing">Pricing</h2>
Linking to a Destination on the Same Page
A link jumps to a destination on the current page by setting its href to a # symbol followed by the target id -- href="#pricing" scrolls the browser directly to the element with id="pricing", without ever leaving the current page or reloading it.
Note: Add these same-page bookmark links to a "table of contents" at the top of long articles so readers can jump straight to a section.
Warning: Omitting the # before the id turns the href into a request for a different page entirely named after the id, which will 404.
Example: Linking to a Destination on the Same Page
<a href="#pricing">Jump to Pricing</a>
<h2 id="pricing">Pricing</h2>
Linking to a Destination on Another Page
A bookmark link can also point to a section of a completely different page by combining a normal file path or URL with the #id fragment -- href="article.html#conclusion" loads article.html and then immediately scrolls to the element with id="conclusion".
Note: Cross-page bookmark links are especially useful for linking directly to a specific FAQ answer or documentation heading from an external site.
Warning: If the target id does not exist on the destination page, the browser simply loads the page normally at the top, with no error shown.
Example: Linking to a Destination on Another Page
<a href="article.html#conclusion">Read the conclusion</a>
Smooth Scrolling to Bookmarks
By default, bookmark navigation snaps instantly to the destination with no animation. Adding scroll-behavior: smooth to the html element makes the browser animate the scroll smoothly instead, giving readers a clearer sense of moving through the page rather than teleporting.
Note: Apply scroll-behavior: smooth globally on the html selector once, rather than on individual links, so all bookmark jumps animate consistently.
Warning: Smooth scrolling can feel sluggish on very long pages with a large scroll distance, so test the perceived speed on your actual content length.
Example: Smooth Scrolling to Bookmarks
<style>
html {
scroll-behavior: smooth;
}
</style>
<a href="#pricing">Jump to Pricing</a>
<h2 id="pricing">Pricing</h2>
Combining Bookmarks with Navigation Menus
Bookmark links are frequently combined into a sticky navigation menu at the top of a page, letting visitors jump between major sections (like Home, Features, Pricing, Contact) without ever triggering a full page reload, which keeps the browsing experience fast and app-like.
Note: Highlight the current section's nav link as active using JavaScript that listens for scroll position, for a more polished single-page navigation feel.
Warning: A sticky nav bar can visually cover the top of a section right after a bookmark jump; pair it with scroll-margin-top on the section to compensate.
Example: Combining Bookmarks with Navigation Menus
<nav>
<a href="#home">Home</a>
<a href="#features">Features</a>
<a href="#pricing">Pricing</a>
</nav>
- Forgetting the # symbol before the id in the href, which turns the bookmark link into a request for a nonexistent separate page.
- Using duplicate id values on the same page, which is invalid HTML and makes bookmark link behavior unreliable since ids must be unique.
- Adding spaces or special characters to an id value, which can break the href="#id" link from matching it correctly.
- A bookmark destination is any element with a unique id attribute, matched by a link's href="#id" value.
- Bookmark links can jump within the current page or to a specific section of a different page entirely.
- scroll-behavior: smooth on the html element animates bookmark jumps instead of snapping instantly to the destination.
HTML id-based bookmark links are supported in every browser and have worked since the earliest versions of HTML.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists