HyperText Markup Language
Previous

The HyperText Anchor Tag: Usage


<A> . . . </A>

The hypertext anchor tag is mainly used to link phrases in your document to other resources on the Internet. It is also used to provide "target locations" within a document to jump to from a hypertext reference. Either the HREF= or NAME= attribute is required:

HREF="URI"
When you select the "highlighted text", the document referred to by the URI is loaded and displayed.
NAME="text"
The "text" is a location name (named anchor) to be used as the target of a link. Useful for linking creating internal hypertext links within a single document.
 

 

Absolute References (HREF="full URL")

When you are linking to a document on another server or in another area of the Web site, the full (or absolute) URL is used. In the following example, the phrase "Library of Congress Home Page" will be used at the link text -- when someone selects the highlighted phrase, the browser links to and displays the Library of Congress Home Page (absolute URL -- http://www.loc.gov/).

This coding:

Return to the <A HREF="http://www.loc.gov/">Library of Congress Home Page</A>

Renders:

Return to the Library of Congress Home Page


Relative References (HREF="filename")

The document you are viewing has the absolute URL:

http://www.loc.gov/iug/html/anchor.html

The main home page for this course has the absolute URL:

http://www.loc.gov/iug/html/outline.html

Since both of these pages are on the same server ( http://www.loc.gov/ ) and are in the same subdirectory ( /iug/html/ ), it is possible to reference the page using a relative URL ( outline.html ).

This coding:

Go to the <A HREF="outline.html">HTML Basic Training Class Home Page</A>

Renders:

  Go to the HTML Basic Training Class Home Page

Note - when you mouse over this link, the status line displays the full/absolute URL, as resolved by Netscape or Internet Explore, using the address in the BASE tag.

Relative URLs are preferred over absolute URLs when the files you wish to link to are located in the same directory as the current HTML page. This will save time, if you ever relocate your pages.


Internal Links and Named Targets

An internal link and named target allows you to create hypertext links to "targetted" areas of the current Web page. These can be especially useful for navigating to specific locations in a long document, or for providing an easy way to return to the top of the current page.

Creating internal links is a 2-step process:

  1. Designate a "target" using the <A> tag with the NAME= attribute and give it a name.
  2. Create a hypertext link somewhere else in the document to jump to the target you created.

For instance, the tag to create a named anchor target called "top" would be:

<A NAME="top">text at or near the top of the page</A>

This anchor would not be visible on the displayed page.

In order to link that named anchor/target, a special relative URL is used: instead of a filename, use a pound sign (#) followed by the exact name of the target.

This coding:

Return to the <A HREF="#top">Top of This Page</A>

Renders:

Return to the Top of This Page

Note - when you mouse over this link, the status line displays the full/absolute URL, as resolved by Netscape or Internet Explore, using the address in the BASE tag. Using that full URL, you could link to this internal link on this page from another HTML file on another site.


Linking to Images and Other Multimedia Objects

The URL used in the "HREF" part of the <A> tag can point to any type of files -- even multimendia files like .GIF and .JPG files.

This coding:

Graphic browsers display the image when you select the words <A HREF="http://www.loc.gov/rr/print/guide/pp3869.jpg">Earliest surviving photograph of the US Capitol</A> above. Text browsers like LYNX download the image to your computer account so you can view it later.

Renders:

Graphic browsers display the image when you select the words Earliest surviving photograph of the US Capitol above. Text browsers like LYNX download the image to your computer account so you can view it later.


Go to:


Library of Congress
Library of Congress Help Desk (October 17, 2000)