Site Development Foundations

Chapter 5 - Hyperlinks

Hyperlinks are external links to other web sites or pages on the same site, or internal links to anchor points on the same page.

Set up a hyperlink using the anchor tag, <a> before the text or image to act as the link. Enclose the destination of the link within quotation marks (important!) as the value of the href= attribute. At the end of the text/image, close the link with the </a> tag:

<a href="http://richardbowles.tripod.com">A link to my site</a>
<a href="c:\myfiles\report.html">A link to a file on a hard disc</a>
<a href="../shared/calculate.htm">A relative link to a page somewhere on the site</a>
<a href="images/holiday.htm">My holiday snaps</a>

The first two links above are absolute links, giving the full address of the page. In the first case it is a different site, in the second a file on the hard disc. The other two links are relative links, where the address of the page is given relative to the current position. Links should be given as relative links where possible so that HTML code does not need to be rewritten when the site is moved to another domain name.

If the address is an absolute one and refers to a site on the Internet, you must include a protocol (http:// in the first example above). Protocols are:

In relative links:

You can use an image as a link by including the appropriate <img src="..." /> within the anchor tags. The image will appear with a (usually) blue border round it to indicate it is a link unless you add the attribute border="0" to the image tag.

Creating an internal link

An internal link jumps to a specific anchor point within a file, link this one to the top of this page. Use the <a name="..." /> to mark a point within a page and give it a name e.g.

<a name="main_menu" />

A link to that anchor point from within the same page uses the attribute href="#main_menu" (note the hash sign). There is no need to refer to a file extension or a protocol in this case. You can even refer to anchor points within different pages by combining absolute or relative destinations with the hash notation:

<a href="../intro.htm#main_menu">Click here for the menu</a>

Automatic Link Checking

When pages are moved to different locations or deleted, it is possible that links to them from other pages become invalid. It is important to check links regularly to make sure that they are not "dead". The following sites lead to facilities that will check web sites automatically:


Previous chapter
Summaries menu
Next chapter
Previous chapter
Summaries menu
Next chapter
Hosted by www.Geocities.ws

1