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?
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.
onError
default image
main image
<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
1.1k questions
673 answers
454 comments
193k users
Related Activities
Categories
Most popular tags