HTML onerror event Attribute

❮ HTML Event Attributes


<img src="dummy.png" onerror="myFunction()">

function myFunction() {
  alert("Unable to load the image.");


The onerror attribute is used to capture various events generally related to communication using Ajax, though may apply to arbitrary URL loading using media elements like images, audio, and video. This attribute is also used for catching script related errors.

Standard Syntax

<element onerror="script">

Browser Support


Attribute Values

Value Description
script Specifies the script to be run on onerror

Technical Details

Supported HTML elements:

<img>, <input type="image">, <object>, <link>, and <script>
❮ HTML Event Attributes