I tried to remove the broken icon in the img element when the destination url doesn’t exist, without deleting the img element :
HTML:
<img src="error.png">
CSS:
img {
width: 100px;
height: 100px;
background-image: url(url.png);
background-size: cover;
}
Instead of deleting the img element, I prefer to bring up the background-img without a broken icon.
I hope someone help me, I really need this.
2
Answers
You can use
::before
and::after
for this.Something like this:
According to the answer I found on Stack Overflow, try using
img:after
in combination with thecontent
property.How to hide image broken Icon using only CSS/HTML?
Here you can find the working example: https://codepen.io/filipalbert/pen/QWZxPMp