HTML onload Event Attribute

Description

The event attribute onload allows you to set the script to fire after the page has finished loading completely (including images, external style sheets, and external scripts). It can also be used on some HTML elements.

Syntax

<element onload="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onload event</title> 
    </head> 
    <body> 
    <img src="2.png" alt="CSS" onload="LoadInfo()"> 
    <p id="test"> </p> 
<script> 
function LoadInfo() {
  document.getElementById("test").innerHTML = "Image loaded successfully!";  
} 
</script> 
  </body> 
</html>

Supported Tags

<body>, <frame>, <frameset>, <iframe>, <img>, <input>, <link>, <script> and <style>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
YesYesYesYesYesYes
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesYesYesYes