HTML onload Event Attribute

The HTML onload event attribute is triggered when an object has been loaded in an HTML document.


Following is the syntax −

<tagname onload=”script”></tagname>

Let us see an example of HTML onload event Attribute−


 Live Demo

<!DOCTYPE html>
   body {
      color: #000;
      height: 100vh;
      background-color: #FBAB7E;
      background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
      text-align: center;
      padding: 20px;
   function get() {
      alert("Hi! you just refresh the document.");
<body onload="get()">
<h1>HTML onload Event Attribute Demo</h1>
<p style="color:#db133a;">Now try to refresh this document.</p>


Now try to reload the document to observe how onload event attribute works.