Yes, there are two types of relative URLs: relative URLs with a relative path and relative URLs with an absolute path.
(1) Relative URL with relative path = relative to the current page's URL. Files or resources that need to be linked are located within the same website.
Example, you are on https://example.com/items/menu.html
.
You want to link to an image file in the images
folder in the same directory as the current page, you would use the relative URL src="images/myimage.jpg"
.
The resulting url will be: https://example.com/items/images/myimage.jpg
. This is because, when you don't put /
before images
in src="images/myimage.jpg"
, you are telling the browser that the images
folder is located in the same directory as the menu.html
file.
Imagine, inside example.com
folder, has items
folder, inside items
folder has both images
folder and menu.html
file.
So it will change from https://example.com/items/menu.html
to https://example.com/items/images/myimage.jpg
because images
folder and menu.html
are on the same level when you don't put /
before images
. That's it!
(2) Relative URLs with absolute path = URL that specify the complete path starting from the root directory of the website.
Example, you are on https://example.com/items/menu.html
again.
You have an images
folder at the root directory of the website. P/s: Root directory is https://example.com/
.
You want to link to an image file in root folder, you would use the relative URL with absolute path src="/images/myimage.jpg"
. Notice that it has /
before images
to specify that it will be relative to root directory.
The resulting url will be: https://example.com/images/myimage.jpg
. It will change from https://example.com/items/menu.html
to https://example.com/images/myimage.jpg
because images
folder are on the root directory. That's it!
(3) Long story short,
You are on https://example.com/items/menu.html
.
If you use src="images/myimage.jpg"
,
resulting URL will be https://example.com/items/images/myimage.jpg
.
If you use src="/images/myimage.jpg"
,
resulting URL will be https://example.com/images/myimage.jpg
.
//yolo.com
is considered an absolute url? – Ethylene