Learning HTML
Chapter 4 - HyperText Links

4.2 HyperText References (HREF)

In the example we just looked at, we gave the exact location of a World Wide Web page for Dickinson College ( http://www.dickinson.edu/ ). This type of reference is called an absolute reference. You can also create a link using a relative reference. These references are relative to the document which is being viewed. For example, to create a link to another file within the same directory as your document, you would only need to specify the file name.

Let's create a new document using Notepad to illustrate the different types of references. You should be running Notepad with a new or blank document. Enter the following text:

     <HTML>
     <HEAD>
     <TITLE>HTML Guide - Paul's Second Document</TITLE>
     </HEAD>
     <H2>Paul's Second Document</H2>
     This is my second HTML document. This will illustrate how to use  
     links, which is a powerful feature of HTML.<P>
     <HR>
     I've already created <A HREF="first.html">my first document.</A>   
     If you select that link, you can look at it.<P>
     Here is a link to <A HREF="http://www.dickinson.edu">the Dickinson  
     College home page.</A> Take a look at it.<P>
     <HR>
     </HTML>

When you finish entering the text, save the file with the name second.html. Then use the File Open File command in Netscape to view the file (if you don't remember how, go back to Chapter 2 to review the instructions).

When you view the file in Netscape, click on the highlighted words my first document. That should take you to the file first.html, which is the first document you worked on. This is an example of a relative reference. Because first.html is in the same location as second.html, you only need to provide the file name for the hypertext reference.

If you click on the second highlight, the Dickinson College home page, you will go to their home page located on a World Wide Web server. This is an absolute reference, providing the complete location.

Relative references are very useful when you are creating a series of documents which will be stored together. This HTML guide, for example, uses relative references to link the different parts. It is easier to type a short relative reference:

2.html

than a complete absolute one:

http://www.bsimple.org/learnhtml/chap4/2.html

The chance of error when typing is reduced as well. In addition, if you ever move the documents to a different location, you won't have to change all the relative references.

Absolute references must be used when you are creating links to locations other than your own. For example, if you were listing some of your favorite Web sites, you would provide an absolute reference for each one.


Learning HTML
www.dickinson.edu/~dempsey
Last updated 6/8/2001
Copyright © 2001 Paul Dempsey