Image is not showing in browser | Sololearn: Learn to code for FREE!

0

Image is not showing in browser

Hello I need a help my image in html document or css is not showing in browser, I've tried almost all ways like giving the path, naming the correct file of image to show but still not showing, what should i do now? Image only showing with notepad html code in browser but in ide or editors don't. Help!!

10/5/2021 12:07:57 PM

Lalitkumar Prajapat

1 Answer

New Answer

+3

When you open an html file in a browser from your hard drive it uses the file protocol rather than the http protocol. However, when you open a web page from an advanced editor or ide it may be launching an actual web server connected to localhost, the loopback address. If the image is specified as src="c:\users\username\pictures\image.jpg" or something similar the web server will not be able to access it. If the image is in the same folder as the html page use src="filename.jpg" and it should work in all cases. This is known as a relative URL. It is specified relative to the location of the web page. If the image is in a directory above the web page use src="..\filename.jpg". This may not work in all cases though. If the web server is launched with the location of the current web page set as the root directory for the server it will not permit access to directories above this location. If you try running the web page in the Sololearn code playground the code playground web server has no access to your local file system so it cannot show the image. In this case the image must be uploaded to an image share server and an absolute URL specified e.g. src="https://www.imageshare.com/filename.jpg"