Relative and Absolute Links
  • It is important to note that there are two ways you can reference a document within an HREF attribute. You can reference it absolutely or relatively.

  • An absolute link defines the location of the document absolutely including the protocol to use to get the document, the server to get it from, the directory it is located in, and the name of the document itself.

  • An anchor of this type will look like those we have seen so far...

<A HREF = "">

  • A relative link on the other hand takes advantage of the fact that the server knows where the current document is. Thus, if we want to link to another document in the same directory, we don't need to write out the full URL. All we need to use is the name of the file.

  • For example, if we are looking at the index.html file addressed in the previous example, and we want to link to a file called page1.html in the same directory (Tutorials), we need not write out the entire URL. In fact, either of the following anchor tags will work:

<A HREF = "">
<A HREF = "page1.html">here</A>

  • Similarly, if you wanted to link to a document in the directory "Tutorials/Chapter2/Part1" called "page23.html, you could use the following anchor:

<A HREF = "Chapter2/Part1/page23.html">here</A>

  • This is because the web server will remember the "" part for you.

  • One little technical note here. When you are creating a relative link to a directory under your current one, be careful not to put an initial backslash before the referenced directory. Otherwise, the server will think you are referencing the "root" directory. By example, the following link would be wrong:

    <A HREF = "/Chapter2/Part1/page23.html">here</A>

Previous Page | Next Page