What are the advantages of using relative paths?

What are the advantages of using relative paths?
Aren’t absolute paths more secure? For example if I would move my internal html file accidentally into another folder, the relative path would be incorrect and thus the link dead.
Or would the internal moving change the absolute path as well; so that the absolute path relies 100% on the relative path?

16 Likes

examples of absolute path:

# windows
c:\users\username\pictures\img1.jpg
# *nix
/home/username/pictures/img1.jpg

if then then move the image from pictures to documents, the absolute path would also break.

relative paths are better, given we can then move the entire project to a different computer (which very likely has a different username) and we don’t have to go and find all the absolute paths with the username in it

78 Likes

For some reason, this answer made it very clear to me in a general way the differences and uses of the different types of paths. Thank you @stetim94.

5 Likes

Relative paths are also advantageous if one moves entire website from one domain to a different domain altogether. You do not have to change all local links. For example, imagine a file like www.example.com/images/picture1.jpg. If we realise we want to change our domain to www.site.com because of any other reasons but we want to leave the files intact, the picture1.jpg image will break. But if it is a relative file like /images/picture1.jpg it will still work. So relative links are advantageous when changing domains

3 Likes