Relative image URLs in HTML

Joined
Feb 13, 2023
Messages
1
Reaction score
0
I'm currently learning how to create HTML websites (my main browser is Firefox) and I'm having issues with getting relative image URLs to work, I've managed to get absolute URLs working with Imgur but I believe relative URLs are more reliable? Have I missed something in the guides I'm following? I've pasted the code I've got for the relative URL for reference

<img src="Users/ncorb/Documents/HTML/Images/batman.png">
 
Joined
Nov 23, 2022
Messages
15
Reaction score
0
Relative URLs are only a portion of the URL. You can specify image source based at the current directory.

Example:

<img src="/images/picture.png">
 
Last edited:
Joined
Mar 5, 2023
Messages
36
Reaction score
12
I'm currently learning how to create HTML websites (my main browser is Firefox) and I'm having issues with getting relative image URLs to work, I've managed to get absolute URLs working with Imgur but I believe relative URLs are more reliable? Have I missed something in the guides I'm following? I've pasted the code I've got for the relative URL for reference

<img src="Users/ncorb/Documents/HTML/Images/batman.png">
It looks like you are using a relative file path for the image source in your HTML code. The issue with the current path is that it is an absolute file path on your local machine, which won't work when you upload your website to a server or share it with others.

Instead, you can use a relative file path that is relative to the HTML file that is referencing the image. For example, if your HTML file is located in a directory called "HTML" and your "Images" directory is located in the same directory, you can use the following code to reference the image:

Code:
<img src="Images/batman.png">

This code assumes that your HTML file and your "Images" directory are in the same directory. If your "Images" directory is located in a different directory, you would need to adjust the file path accordingly.

By using a relative file path, your image will be able to load properly regardless of where your website is hosted or accessed from.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top