HTML onload Event Attribute

Example

Execute a JavaScript immediately after the page is loaded:

<body onload="load()">

Try It Yourself

Browser Support

IE Firefox Chrome Safari Opera

All major browsers support the onload attribute.

Definition and Usage

The onload attribute triggers when the object is loaded.

onload is commonly used in <body>, and a script is executed once all content is fully loaded (including images, script files, CSS files, etc.).

Differences between HTML 4.01 and HTML5

None.

Syntax

<element onload="script">

Attribute Value

Value Description
script Script runs when onload occurs.