Adding Internal Links

Using the Anchor Tag to Create Page Bookmarks

A business man working at office
Kohei Hara/Digital Vision/Getty Images

When you're working on an HTML document and you want users to be able to click on a topic and be instantly transported to a bookmarked location within the document, anchor tags come in handy.

HTML documents frequently include external links to other documents, but they also can include links within a single document. Clicking on one tag transports the reader to a specific bookmarked section on the web page.

Eventually, it may be possible to link to exact pixel locations in documents, but for now you need to use the anchor tag to create both the link and the location it links to. Anchor tags usually appear in pairs. One tag identifies the link, and the second tag identifies the destination. Essentially anchor tags form bookmarks within an HTML document.

In the document, decide where you want the internal links to go. You label these using the anchor tag with the name and id attributes. The name and id attributes should be identical. For example:

<a name="anchor1" id="anchor1">Anchor text</a>

Next, you create the link to the section of the document using the anchor tag and the href attribute. You indicate the named area with a #.

<a href="site.html#anchor1">Anchor link</a>
The trick is to make sure that you put the​ <a name>  around text or an image. For example:
<a name="here">Here</a>

Many times you see people use these links without surrounding anything (for example, ), but this is not as reliable an anchor as one that surrounds a word or image.

Many browsers prefer to have some element to position at the top of the screen; when you enclose nothing, you run the risk that the browser will be confused.