This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



The body element (<body>) represents the main content of the document.

Overview Table

DOM Interface

You can access the <body> element from script through the document object.

The window object for the <body> element can host event handlers for the onblur, onfocus, onload, or onunload events.

HTML Event Handler Content Attributes

onafterprintUser printed current document.
onbeforeprintUser requested printing of current document.
onbeforeunloadDocument is about to be unloaded.
onblurDocument lost focus.
onerrorDocument failed to load properly.
onfocusDocument received focus.
onhashchangeFragment identifier part of the document’s current address changed.
onloadDocument finished loading.
onmessageDocument received a message.
onofflineNetwork connections failed.
ononlineNetwork connections returned.
onpopstateUser navigated session history.
onredoUser went forward in undo transaction history.
onresizeDocument view was resized.
onstorageStorage area changed.
onundoUser went backward in undo transaction history.
onunloadDocument is going away.

The following attributes are obsolete, and should not be used by authors: alink, bgcolor, link, marginbottom, marginheight, marginleft, marginright, margintop, marginwidth, text, vlink.


The <body> element follows the <head> element and is contained by the <html> element.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>The HTML Document</title>
<p>The HTML content</p>
[View live example](

This example exposes the <body> element in javascript.

var oBody = document.body;

Related specifications

HTML 5.1
W3C Working Draft
W3C Recommendation
HTML 4.01
W3C Recommendation