<body onLoad="">

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
Attribute of
HTML Body Tag: Master The Most Important HTML Element Now
What does <body onLoad=""> do?
Fires a script when the page has finished loading.

The onLoad attribute is an event handler that instructs the browser to run a script when the visitor loads the page. This is commonly used to forward the visitor to another page, but can be used to trigger pop-up boxes, or execute a script based on the user’s browser version.

Example usage

<body onLoad="script"> 

Points to be aware of

body event handlers act on the browser window, and the script will only be executed once the page is completely finished loading. Because of this, onLoad can’t be used to change the size or properties of the browser window. The opposite command, onUnload, often yields more reliable results than onLoad.

Claire is seasoned technical writer, editor, and HTML enthusiast. She writes for HTML.com and runs a content agency, Red Robot Media.

Browser Support for onLoad

iefirefoxchromeedgesafariopera
AllAllAllAllAllAll