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 another 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 the absolute and relative paths is that the 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.
Since 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 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 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 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.
They may also change from country to country.
For example, an absolute path on a Windows system may look something like this –
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 “\”.
The current working directory does not affect an absolute path 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 it has access to, servers must 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 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 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 in the same domain.
Although relative paths do not begin with delimiting characters, they may look different on different operating systems.
For example, a relative URL on a Windows system would look something like this –
Similarly, a relative URL on a Linux system looks like –
Relative paths hold less information and tell us less 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. A relative path describes a file’s location 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 the differences between these links and which type of link will be used in each scenario.
To summarise, if you ever link to a file 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.
I’ve put so much effort writing this blog post to provide value to you. It’ll be very helpful for me, if you consider sharing it on social media or with your friends/family. SHARING IS ♥️
Sandeep Bhandari is the founder of ExactlyHowLong.com website.
I am a professional full-time blogger, a digital marketer, and a trainer. I love anything related to the Web and I try to learn new technologies every day.
All the team management, content creation, and monetization tasks are handled by me. Together with the team at ExactlyHowLong, the aim is to provide useful and engaging content to our readers.
In game development, I love playing with every different engine, toolset, and framework I can find. In digital art, I love everything from painting to vector work to pixel art to 3D modeling.
In short, if it’s creative and you can make it digitally, I love it.