Let's say following is the directory structure of my website :
Now in index.html
I can simply refer images like:
<img src="./images/logo.png">
But I want to refer the same image from sub.html
. What should be the src
?
You can reference the image using relative path:
<img src="../images/logo.png">
__ ______ ________
| | |
| | |___ 3. Get the file named "logo.png"
| |
| |___ 2. Go inside "images/" subdirectory
|
|
|____ 1. Go one level up
Or you can use absolute path: /
means that this is an absolute path on the server, So if your server is at https://example.org/, referencing /images/logo.png
from any page would point to https://example.org/images/logo.png
<img src="/images/logo.png">
|______ ________
| | |
| | |___ 3. Get the file named "logo.png"
| |
| |___ 2. Go inside "images/" subdirectory
|
|
|____ 1. Go to the root folder