DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

How to Create a Bookmark in HTML: Use an ID and a Link Fragment

An HTML bookmark is a link to an element ID. Add a unique, non-empty ID to the destination—often a heading, paragraph, or table cell—and link to it with a URL fragment.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a bookmark within an HTML document, give the destination element a unique, non-empty id, then link to it with href="#that-id". Put the ID on the heading, paragraph, or table cell that represents the destination; an empty anchor or div is usually unnecessary.

How to create an in-page bookmark

In modern HTML, a “bookmark” is an element identified as the destination of a URL fragment. The WHATWG HTML Standard describes an element’s unique identifier as a way to link to a specific part of a document using fragments.

As an Amazon Associate I earn from qualifying purchases.

  1. Add a unique, non-empty id to the element you want readers to reach.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. Link to that ID by putting a hash (#) and the same value in the link’s href.

    #1 Best Overall
    Sale
    HTML and CSS: Design and Build Websites
    • HTML CSS Design and Build Web Sites
    • Comes with secure packaging
    • It can be a gift option
<p>Here we are talking about <a href="#carrot">carrot cake crackers</a>.</p>

<h2 id="carrot">Carrot Cake Cracker</h2>
<p>These are the ingredients you need.</p>

Clicking the link navigates to the element whose ID is carrot. For a link from another page, append the same fragment to that page’s URL, such as https://example.test/recipe#carrot.

Where to put the ID

Attach the ID to the existing element that best represents the destination. For a section, that is commonly its heading; for a specific passage, it may be a paragraph. If the intended destination is in a table, put the ID on the relevant cell or other element that identifies the destination.

<table>
  <tr>
    <td id="ingredients">Flour, sugar, and carrots</td>
  </tr>
</table>

<a href="#ingredients">See the ingredients</a>

Why an ID on existing content is usually better than an empty anchor

The May 2014 SitePoint discussion asked whether to use an empty div, an empty a, or an ID on existing content. Its practical recommendation is to put the ID on the paragraph, heading, or table cell that is actually the destination. That avoids adding a separate, empty element when meaningful content already marks the location.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use an empty element only when there is no suitable existing element to identify as the target. The key is that the fragment must match an ID on the destination element.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Rules for IDs and older bookmark markup

For links in the same document, the fragment is simply #id-value. For links from another document, use that page’s URL followed by #id-value.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.