Relative vs. Absolute Links
When and How to Use Them
A link is an if the URL and file name can be found from anywhere on the Web, not just from a single Web site. An absolute link specifies a fully-qualified URL; the protocol must be present in addition to a domain name, and often a file name must be included as well.
For instance:
The URL in this link can be browsed to regardless of where one starts.
[It's important to remember that a URL should include a protocol (in this case, ). Even though your links may work on your computer without the protocol being spelled out, you should include it anyway -- for people whose computers don't understand that a web address should have in front of it.]
A specifies the name of the file to be linked to only as it is related to the current document.
For example, if all the files in your Web site are contained within the same directory (or folder), and you want to establish a link from to , the code on will be:
This link will be valid only from within the same directory that is saved in.
Relative links, and their paths, can be tricky. For example, imagine that is in the root directory (or main folder) and is in a subdirectory named . In that case, a link from to would be coded:
In other words, instead of typing the file name, you would first type the folder (directory) name, a forward slash, and then the file name.
[By the way, both folder names and file names are case-sensitive in URLs. The files and are two different files. However, domain names are not case-sensitive; typing will get you to the same exact place as will .com.]
And suppose you want to link back to from ? The code to link to a file in a directory above the directory in which the current file is contained would be:
Each time you want to move up a level in the folder hierarchy, you must type two periods and a forward slash .
Let's assume now that your Web site's folder structure looks something like this: in your root directory, you have a folder named ; and in , there's yet another folder (or directory) which is named (fig. 1).

Fig. 1
To link a page named -- which resides in -- to (in the root directory) you would code:
In other words, you'll use the code each time you want to indicate a move one directory up.
Let's look at one final example. Imagine now that the root directory contains two folders, one named and one named (fig. 2).

Fig. 2
Let's say your mission is to link from in to in . To do that, you must first move up one level to the root directory, and then down one level to . The code will look like this:
So why not use absolute links all the time? One consideration is that they'll add bulk to your code. Another -- especially if you have dialup internet access -- is that you can verify relative links even when you're offline.
Cost of the War in Iraq
(JavaScript Error)
|