How to create a placeholder image in HTML if the original image was not found?

Basically what the title says.

I create an html page and use images for reference. But can I make the images display by default if the specified file was not found?

+5
source share
5 answers

If you specify the width and height of the image in css, you can set the background image as not found image:

img {
  width:100px;
  height:100px;
  background: url(http://goo.gl/vyAs27) no-repeat scroll 0 0;
}
<img src="not-found.png" /><img src="http://goo.gl/ijai22" />
Run codeHide result

Most browsers insert an image that is not in the corner. I do not know how to remove it.

As you can see, your regular image overlays a background image.

, .

, , . , ...

+10

javascript:

<img src="404image" onerror="this.src='images/not_found.png';" />
+26

- /, alt, img.

<img src='not_found.jpg' alt='' class=''>

not_found.jpg - , . PFA o/p.

  • , src, - .

Here the 1st image is shown when it becomes a valid src, and the second shows an empty space without any caption.

+1

Hey, you can easily place an image, just put it in HTML

http://placehold.it/image size

0
source

Set the resolution of the image that you need. For example, I need an image size: 100X100. insert the path to the image or set the correct path to the image source for your folder.

CSS:

img {
   width:100px;
   height:100px;
}

HTML:

<img src="https://dummyimage.com/100/00ff48/ff0000.png&text=Image+Found" alt="not found image" />
0
source

Source: https://habr.com/ru/post/1609987/


All Articles