Skip to content
HTML and CSS

Hiding Broken Images in HTML

1 min read

A nice write-up on styling broken images has appeared online by bitsofco.de in the last 24 hours; however, if you want a simple way of completely hiding a broken image you can just use the onerror attribute of the <img /> tag to hide the image element like this:-

<img src="broken.png" onerror="this.style.display='none'" />
© 2024 Andy Carter