Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Using Named Anchors

Figure 7.1 demonstrates the use of intrapage links. To see how such links are made, take a look at the first <a> tag in Figure 7.1:

07fig01.gif

Figure 7.1 An <a> tag with a name attribute acts as a marker, so <a> tags with href attributes can link to that specific point on a page.

<a name="top"></a>

This is a different use of the <a> anchor tag; it simply gives a name to the specific point on the page where the tag occurs. The </a> tag must be included, but no text between <a> and </a> is necessary.

Now look at the last <a> tag in Figure 7.1:

<a href="#top">Return to Index.</a>

The # symbol means that the word top refers to a named anchor point within the current document, rather than to a separate page. When a reader clicks Return to Index, the Web browser displays the part of the page starting with the <a name="top"> tag.

Here's an easy way to remember the difference between these two different types of <a> tags: <a href> is what you click, and <a name> is where you go when you click there.

An anchor is a named point on a Web page. The same tag is used to create hypertext links and anchors (which explains why the tag is named <a>).

Similarly, each of the <a href> links in Figure 7.1 makes an underlined link leading to a corresponding <a name> anchor. Clicking the letter B under alphabetical index in Figure 7.2, for instance, takes you to the part of the page shown in Figure 7.3.

07fig02.jpg

Figure 7.2 The <a name> tags in Figure 7.1 don't appear at all on the Web page. The <a href> tags appear as underlined links.

07fig03.gif

Figure 7.3 Clicking the letter B in Figure 7.2 takes you to the appropriate section of the same page.

Share ThisShare This

Informit Network