It is hard to imagine today’s world without the internet. Nearly an uncountable number of files are shared every single day through the means of the internet.
in the early days of computers, most files were shared through CDs, DVDs, Floppy Disks and USB Pen drives.
Today, most of these files are shared online through links. These links help us jump from one spot to the other on the internet.
These links are of two types, absolute and relative, depending on the location path they describe.
Absolute Path vs Relative Path
The main difference between absolute path and relative path is that absolute path describes the file’s location from the root directory.
On the other hand, a relative path describes the location of a file related to the current working directory.
Absolute Path contains the complete location of a file or a directory.
Considering that absolute paths describe the location of the root path, they contain all relevant information to find resources indicated by an absolute URL.
Relative paths are best used to refer to websites that are located on the same domain as they do not describe the location of the root directory.
Comparison Table Between Absolute Path and Relative Path
|Comparison Parameter||Absolute Path||Relative Path|
|Definition||Absolute Paths describe the location of a file from its root directory.||Relative Paths describe the location of a file from its current working directory.|
|Type of URL Used||Absolute URLs use absolute paths to link to certain files.||Relative URLs use relative paths to link to certain files.|
|Generally Navigates to||Absolute URLs are used when the file being referred to is not on the same domain.||Relative URLs are generally used when the file referred to by the link is on the same domain.|
|Delimiting Characters||Absolute URLs generally begin with a delimiting character such as “/”.||Relative URLs never begin with a delimiting character.|
|Also Known As||Absolute paths are also known as full paths or file paths.||Relative paths are also referred to as non-absolute paths.|
What is Absolute Path?
Absolute URLs, that use absolute paths, which describe the location of a file from the root directory.
The absolute path begins from the root location of the file and leads to the location. It always includes a full path to the location.
Absolute paths are generally used to link to files that are not on the same domain as these URLs are detailed and point to a specific location.
Absolute URLs often begin with delimiting characters such as “/” or “\” that depend on the operating system that is being used.
They may also change from country to country.
For example, an absolute path on a windows system may look something like –
An absolute path on a Linux system looks like –
Korean or Japanese directories may use ¥ or ₩ as a directory separator instead of the standard “/” or “\”.
An absolute path is not affected by the current working directory and will always begin with the root location.
Absolute paths are easier to understand as they give the full location. However, this can make them inconvenient to work with as each step from the root directory needs to be specified.
To locate the files that it has access to, servers are required to know the absolute path for every single file.
This is not true when it comes to working with Wordpress. The only time you would require the absolute path of a file in Wordpress is when you are a developer and must reference the exact location of a file that you are writing code for.
To find the absolute path of files used for WordPress, you can write three simple lines of code in PHP and store that information on your web server for use as a reference.
What is Relative Path?
Relative URLs, that use relative paths to link to files, describe the location of a file from the current working directory.
The relative path disregards the information needed to locate the current working directory from the root directory and only focuses on the route from the working directory to the entity.
Relative paths are generally used to link to files that are in the same domain.
Although relative paths do not begin with delimiting characters, they may still look different on different operating systems.
For example, a relative URL on a windows system would look something like –
Similarly, a relative URL on a Linux system looks like –
Relative paths hold less information and tell us lesser about the root of the file. Still, relative paths are easier to work with as they are shorter and more convenient.
This point is especially highlighted when working with deeply nested directories.
Main Differences Between Absolute Path and Relative Path
- Absolute paths describe the location of a file from its root directory. Whereas, a relative path describes the location of a file related to its current working directory.
- Absolute URLs use absolute paths and relative URls use relative paths.
- Absolute URLs are used to link to pages which are not on the same domain. On the other hand, relative URls are generally used to link to pages that are on the same domain.
- Absolute URls generally begin with delimiting characters such as “/”, “\”, “,”, “:” etc.
Relative URLs do not begin with delimiting characters.
- Absolute Paths are also known as full paths or file paths. Relative paths are also known as non-absolute paths.
In today’s world, it is important to know which the differences between these types of links and which type of link is to be used in which scenario.
To summarise, if you are ever to link to a file that is not located on the same domain, you are likely to use an absolute URL.
On the contrary, relative URLs will come in handy when you want to link to files on the same domain.