onload HTML Attribute

The "onload" attribute in HTML is an event attribute that can be added to an element, that when triggered, runs a script after the element has finished loading. The attribute value is a string containing the JavaScript code that should be executed when the event is fired.

For example, in the following code snippet, the onload attribute is used to alert the user after an image has finished loading:


<img src="image.png" onload="alert('Image loaded')">

The onload attribute is typically used to listen for when an element has finished loading, and can be used to perform an action or to update the page with the loaded content. This attribute can be used on the body and frameset elements, as well as on images, scripts, iframes and other elements that can be loaded.

It's worth noting that the onload attribute is widely supported by all modern browsers, and also it is a standard attribute, which means it is part of the official HTML specification.

In summary, the "onload" attribute in HTML is an event attribute that can be added to an element, that when triggered, runs a script after the element has finished loading. It's typically used to listen for when an element has finished loading, and can be used to perform an action or to update the page with the loaded content. This attribute can be used on the body and frameset elements, as well as on images, scripts, iframes and other elements that can be loaded. It is widely supported and is a standard attribute, which means it is part of the official HTML specification.