If I'm working on a site and receive HTML content from another source and that source contains images it will show a "broken image" image.
Is there a way for me to define the broken image for the entire page using HTML or CSS and as an absolute last resort JavaScript function. A HTML or CSS option is preferred?
For example, let's sat your job was to replace every broken image with a picture of a rose. Would love CSS or HTML solution.
img {
width: 100px;
height: 100px;
}
img:invalid {
border: 5px solid #ff0000;
}
img:error {
border: 5px solid #ff0000;
}
div {
background-color: lightblue;
width: 100px;
height: 100px;
position: absolute;
top: 100px;
left: 100px;
}
<div>Here is some content next to an image that does not exist <img id="image" src="nothing.jpg">
</div>
Here's what it looks like:
There are new CSS error selectors like invalid and error. Would it be a good idea to consider a pseudo-selector to match broken images?
This question wants to request answers related to those solutions.
Related but not CSS preferred:
Inputting a default image in case the src attribute of an html <img> is not valid?