Languages
[Edit]
EN

HTML - display text message when image is not loaded correctly

3 points
Created by:
Kevin
797

In this article, we would like to show you how to display text message when the image is not loaded correctly in HTML.

Quick solution:

There are many reasons that may cause image loading errors: incorrect URL, network connection problems, incorrect server configuration, incorrect image file.

 

Practical example

Edit

In this example, we display text message when the image isn't loaded correctly using alt attribute. The message about loading error is displayed in the console too using onerror event.

References

Edit
  1. <img>: The Image Embed element - HTML | MDN

Alternative titles

  1. HTML - display text message on image loading error
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join