1

I was trying to put an image from my system to my webpage by giving the address of the image as image source, but the image doesn't show there. I don't face this problem while using a URL as an image source. Can anyone please tell me how to put an image from the system itself on a webpage?

 <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>CSS Display property</title>
    </head>
    <body>
        <header class="top">
            <img src="E:\Folders\ichchha.jpeg"/>
            <h3>Welcome to Ichchha's Blog</h3>
        </header>
    </body>
    </html>
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Does this answer your question? [Why can't I do ?](https://stackoverflow.com/questions/4090712/why-cant-i-do-img-src-c-localfile-jpg) – Nico Haase Dec 08 '21 at 09:33

1 Answers1

0

The src attribute for an <img> should contain a URL, not a file name. The usual way to get an image into the page would be to move it to the same directory as the HTML file and use a relative URL:

<img src="ichchha.jpeg"/>

If you are opening the HTML file locally (without a webserver) and you really need to have it load the image from that particular absolute file path, you could do so like this:

<img src="file:///E:/Folders/ichchha.jpeg"/>

Note that file: URLs use the file:/// prefix and use forward slashes between directories rather than backslashes. The problem with this solution is that isn't going to work when your HTML file is hosted on a web server. It will only work when your HTML file is loaded from a file:/// URL itself.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • Thanks a lot, @Stephen Ostermiller. Just one more question, by hosting locally did you meant creating a localhost port from the terminal? – Ichchha Gupta Dec 03 '21 at 16:23
  • No, I mean opening the HTML file locally from a file, not using a local web server. If you are serving the HTML though a web server, even a local one, you won't be able to load images with `file:` URLs because browsers prevent that for security and privacy reasons. – Stephen Ostermiller Dec 03 '21 at 16:32
  • thankyou, I get it now. – Ichchha Gupta Dec 03 '21 at 17:10