Absolute and Relative Paths

If you're specifying the path of an image, you can use either an absolute path or a relative path. The same thing applies if you're creating a link to another web page document.

Absolute Paths

An absolute path means that the entire path is specified. Examples would be:

http://www.computer-answers.info/Images/Image_1.jpg
http://www.computer-answers.info/index.php

The advantage of using absolute paths is that there's no ambiguity, and therefore less room for error.

Relative Paths

Rather than specifying the entire path to the destination, a relative path only specifies the location relative to the current document. There are 4 different forms that this can take:

filename (e.g. "Image_1.jpg")
Specifying just the filename means that the file you're referencing must be in the same directory as the web page that references it.
directory/filename (e.g. "Images/Image_1.jpg")
In this case, both a directory and a filename are specified. The specified directory must be located in the same directory as the current web page, and the filename must be located in it. You can specify multiple directory levels.
../directory/filename (e.g. "../Images/Image_1.jpg")
Again, both a directory and a filename are specified. This time however, the specified directory is located one level up from the directory that contains the current web page. Again, you can specify multiple directory levels.
/directory/filename (e.g. "/Images/Image_1.jpg")
Again, both a directory and a filename are specified. This time however, the specified directory is located in the root directory of the website that contains the current web page. In our case, for example, this would mean searching for the file in our root directory (http://www.computer-answers.info), regardless of which subdirectory the current page is located in.

Absolute vs Relative Paths

An advantage of relative paths is obviously that they're shorter. Another advantage is that if you maintain the same directory structure on your own computer as on your website, then you can view your pages offline and the links will still work.

Note that this doesn't apply to links of the form /directory/filename, since they're relative to the root directory of the website. If you're viewing a web page offline, then this will be interpreted as the root directory of your computer, which won't be correct unless you've replicated your website's directory structure in your computer's root directory.

The advantage of relative paths is that there's no ambiguity - you can see the full path so you know exactly where the target file is located.

Whether you choose to use absolute or relative paths is larely a matter of personal preference.

<-- Previous Page

Image Width and Height

Next Page -->

Links and Anchors