Inputting a default image in case the src attribute of an html img tag is not valid?

I have seen so many blogs on this topic but they haven’t been able to give a straight forward answer and that’s why i have come to make this simple and easy to follow. I have got the right method here for you.

Since the first image doesn’t exist, the fallback will display. And if you’re using a really old browser that doesn’t support object, it will ignore that tag and use the img tag.. This element is widely supported by all browsers from IE6+.

* Unless the URL for the image changed (again), in which case you’ll probably see the alt text

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>
  <title>Object Test</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>

  <p>
    <object data="http://stackoverflow.com/does-not-exist.png" type="image/png">
      <img src="https://cdn.sstatic.net/Img/unified/sprites.svg?v=e5e58ae7df45" alt="Stack Overflow logo and icons and such">
    </object>
  </p>

</body>

</html>

I hope this was helpful 🙂