Open In App
Related Articles

HTML onerror Event Attribute

Improve Article
Save Article
Like Article

This attribute works when an error occurs while loading an external file. The external file may contain document file or image file.

Supported Tags

  • <input type=”image”>
  • , <object>
  • , <link>
  • , <script>


<element onerror = "script">

Attribute Value: This attribute contains single value script which works when onerror event attribute call. This attribute is supported by <img>, <input type=”image”>, <object>, <link>, and <script> tags.



<!DOCTYPE html>
    <title>onerror event attribute</title>
        body {
        h1 {
    <img src="image.gif"
    <h2>onerror event attribute</h2>
        function myFunction() {
            alert("The image could not be loaded.");


Supported Browsers: The browser supported by onerror attribute are listed below: 

  • Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 12.1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 04 Aug, 2023
Like Article
Save Article
Similar Reads
Related Tutorials