html tutorial - onload Attribute in HTML - html5 - html code - html form

Onload attribute in html

Learn html - html tutorial - Onload attribute in html - html examples - html programs

  • The onload attribute executes a script when an object has been loaded.
  • onload is most often used within the <body> element to execute a script once a web page has entirely loaded all content (including images, script files, CSS files, etc.).
  • For input elements, the onload attribute is only supported though <input type="image">
  • The onload attribute may be used to check the user's browser type and version, and load the proper version of the web page based on the information.
  • The onload attribute is a section of the Event Attributes.

Syntax for onload attribute in HTML:

<element onload="script">

Applies To:

Elements Attribute
<body> onload
<iframe> onload
<img> onload
<input> onload
<link> onload
<script> onload
<style> onload

Sample Coding for onload Attribute in HTML:

Tryit<!DOCTYPE html>
        <title>Wikitechy HTML onload attribute</title>
        function onLoad() 
          alert("Wikitechy Page is loaded")
    <body onload="onLoad()">
        <h2>Welcome to Wikitechy!</h2>

Code Explanation for onload Attribute in HTML:

onload Attribute Code Explanation

  1. function onLoad () is a JavaScript function which is used to create an alert box when onload attribute is executed.
  2. The onload attribute executes when an associated element has been loaded.

Output for onload Attribute in HTML:

onload Attribute Tag Output

  1. When the page has been loaded the alert box displayed on the browser.
  2. onload Attribute Tag Output

  3. After clicking the ok button, the page has been displayed with the text welcome to Wikitechy!.

Browser Support for onload Attribute in HTML:

Yes Yes Yes Yes Yes

Related Searches to onload Attribute in html