HTML – Hide the default broken image icon

<img src="Error.src" onerror="this.style.display='none'"/>
<img src="Error.src" onerror="this.src='fallback-img.jpg'"/>

The above method also works for the <image> in <svg>.

Reference: StackOverflow – How to hide image broken Icon using only CSS/HTML (without js)

One thought on “HTML – Hide the default broken image icon”

Leave a reply to wayne Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.