Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.6k views
in Web Development by 2 2 3

I want to set a default image for any broken image in my ASP.net web page using CSS, Is it possible to replace broken image using CSS?

Replace broken image CSS


1 Answer

0 like 0 dislike
by 159 198 381

Replace broken image CSS

Actually, there is no CSS property that you can use to replace broken images, instead, you should use JavaScript to add onError event that would fire and show your default image if the main image was broken.

<img src="Main image URL"  onError="this.onerror=null;this.src='default image URL';" />

You might also like to read Replace broken image JavaScript In ASP.NET

If you don’t ask, the answer is always NO!
...