Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

HTML onerror Attribute


Definition and Usage

The error event occurs when an error occurred during the loading of a media file.


Applies to

The onerror attribute is part of the Event Attributes, and can be used on the following elements:

Elements Event
<audio> onerror
<body> onerror
<embed> onerror
<img> onerror
<link> onerror
<object> onerror
<script> onerror
<video> onerror

Examples

Audio Example

Run "myFunction" if an error occurs during loading:

<audio onerror="myFunction()">

Video Example

Run "myFunction" if an error occures during loading:

<video onerror="myFunction()">


Browser Support

The onerror attribute has the following browser support for each element:

Element
audio Yes 9.0 Yes Yes Yes
body Yes Yes Yes Yes Yes
embed Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
object Yes Yes Yes Yes Yes
link Yes Yes Yes Yes Yes
script Yes Yes Yes Yes Yes
video Yes 9.0 Yes Yes Yes