Custom Search

Absolute Path and Relative Path Explained

Web pages consist of web links. The links can send users either to external sites or to pages on the same site which is internal links. Internal links can be created by using either absolute path or relative path.

Relative path is a path relative to the current page's path location. Current page is the page that contains the URL link.

Absolute path is a path that starts with domain URL. Absolute path can be a full path or take the form of a short version. The short version always starts with a forward slash, which is the part of a full URL without the domain name part.


When you link to a page on your own website, always use the short version of an absolute path or use relative path. This speeds up page load time because you have told web server that the linked page is located on the same site.

Another advantage of avoiding the use of full version of absolute path is that if you ever need to change domain name for your site, the links are not going to break. This is because you didn't hard code your old domain name into the links with full version of absolute path.

When you link to a page on another website, you can only use full absolute path. That is a full URL.

Absolute Path and Relative Path Examples

The following table shows you examples of the various paths. We assume current page location is:

Type Level Absolute Path (full version) Absolute Path (short version) Relative Path
Directory Current /products/sales/july/  
File Current /products/sales/july/index.html  
Directory 1 Level Up /products/sales/ ../
File 1 Level Up /products/sales/summary.html ../summary.html
File 1 Level Up /products/sales/services/index.html ../services/index.html
Directory 2 Level Up /products/ ../../
File 2 Level Up /products/demo.html ../../demo.html
File 2 Level Up /products/category/index.html ../../category/index.html
Directory 3 Level Up / ../../../
File 3 Level Up /index.html ../../../index.html
File 3 Level Up /aboutus/index.html ../../../aboutus/index.html
Directory 1 Level Down /products/sales/july/images/ images/
File 1 Level Down /products/sales/july/images/product1.jpg images/product1.jpg

When you link to a page located two directories up from the current directory, it will be like this:

  • Short version of absolute path: <a href="/products/category/index.html">

  • Relative path: <a href="../../category/index.html">

That's because your current page location is


Related Articles:

1.The Difference Between Dynamic URLs and Static URLs
2.Robots Meta HTML Tag Syntax Explained
3.What If You Don't Want Your Pages To Be Crawled and Cached by Search Engines
4.What Robots.txt is And Search Engine Robots Explained
5.The Right Domain Name Drives More Website Traffic

Other Recent Articles from the Web Development category:

1.Java / JSP lost session value on redirect - FIXED
2.Fix the problem with PHP5 XML removeChild() method
3.How to integrate PHP HTML Help .chm file with Crimson Editor
4.How to Connect to a MySQL Database from PHP
5.Use MySQL String Functions to Build Printable ASCII Character Chart
6.Five ways to create include path for PHP
7.How to use Date and Time data as integer value in PHP and MySQL

Copyright © 2017 All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

Home | Feedback | Terms of Use | Privacy Policy