banner
Welcome to HTML.co.uk, the number one resource for all news, information, and happenings regarding HTML.

Updates: HTML.co.uk has just been relaunched. Subscribe to our RSS Feed to stay on top of HTML news and techniques.
Jun
3rd

Absolute and Relative URLs

Author: Editor | Files under HTML Tutorials
Tags for this article: , , , , , ,

As discussed earlier URLs (Uniform Resource Locators) are the addresses of all the links and resources which are globally hosted on the World Wide Web. A web page address like http://www.yahoo.com is a URL. It shows you the home page of Yahoo. In other words, it redirects you to a new URL. URL is one of the most vital elements of HTML. Without URL we cannot access any website. Every URL on the world wide web is unique and different from other to avoid confusion and clashing between the web pages of different companies. The URL consists of all the necessary information required to find out a particular web page on the internet. In HTML whenever we create a hyperlink, we associate a URL with it so that whenever a person clicks on that link, he can be redirected to the intended web page. The URLs are inserted in the HTML codes with the help of anchor tag. We can either specify an Absolute URL or a Relative URL depending upon the circumstances. Let’s have a look on how these two types of URL differ form each other.

Absolute URLs: Absolute URLs are those URLs which do not depend on any kind of relationship. These URLs directly point towards the directory of a file. It represents the whole path to a filename. Thus, there is no confusion about the location of that file on the server. For example:

http://www.contentmantra.com/design/ urls.php3

is an absolute URL which specifies the whole path to the urls.php3 file which is stored in design directory. The main disadvantage of these URLs is if you move the urls.php3 file to another location, then this URL will not show you that file. Thus, the flexibility to change the structure of the web pages diminishes. Absolute URLs are used when we want to link two files which reside in different root directories.

Relative URLs: These URLs point towards a file or directory in relation to the current file and directory. The relative URLs don’t tell us about the full path to a file name. These URLs simply redirects you to the another web page which is in relation to the previous one. Thus, they are called relative URLs. These types of URLs can be used to link different files which are in the same root directory. In other words these URLs are used with those links of a web page which redirects you to another web page of the same website. If all the files are stored under the same parent directory, then both absolute and relative URLs can be used but conventionally relative URLs are used because they are short and reduce the chances of typographic errors. Apart from this, relative URLs are easy to remember and save time while designing the HTML page.

For example; suppose there is a parent directory in c:\my folders\HTML which contains two files named as Summer.html and Winter.html respectively. Now in order to link these two files we don’t have to give the full path. We can simply write as:

<a href=”winter.html”> go to Winter Page</a>

Instead of:

<a href=” c:\my folders\HTML\winter.html”>got to winter page</a>

Post a Comment