How do I add an image to my web page if the image is not in the same dir as the html file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I add an image to my web page if the image is not in the same dir as the html file?

I tried <img src="C:\Documents\...." alt=""/> but it doesn't work. Can someone help me?

7th Jan 2017, 3:54 PM
infinity
infinity - avatar
3 Answers
+ 4
Try using the path like so: <img src="images/1.jpg" /> obviously changing the path to your image but make sure to include yourimage.jpg using this approach you can just create a folder in the same directory as your html file and name it images, a tip is not to use file:/// paths because you're most likely to upload your project on a webserver making the path unavailable.
7th Jan 2017, 4:01 PM
Alex
Alex - avatar
+ 3
For use an absolute path, and local files, you need to prefix it by 'file:///' ( instead the 'http://' ), or simplest use an relative path...
7th Jan 2017, 3:58 PM
visph
visph - avatar
+ 2
you can go back src="../../folder/image.png" ../ means go back one folder
7th Jan 2017, 4:39 PM
ASNM
ASNM - avatar