HTML: The Markup Language (an HTML language reference)

bodydocument body # T

The body element represents the body of a document (as opposed to the document’s metadata).

Permitted contents #

Permitted attributes #

global attributes
Any attributes permitted globally.
onafterprint = functionbody NEW #
User printed current document.
onbeforeprint = functionbody NEW #
User requested printing of current document.
onbeforeunload = functionbody NEW #
Document is about to be unloaded.
onblur = functionbody #
Document lost focus.
onerror = functionbody NEW #
Document failed to load properly.
onfocus = functionbody #
Document received focus.
onhashchange = functionbody NEW #
Fragment identifier part of the document’s current address changed.
onload = functionbody #
Document finished loading.
onmessage = functionbody NEW #
Document received a message.
onoffline = functionbody NEW #
Network connections failed.
ononline = functionbody NEW #
Network connections returned.
onpagehide = functionbody #
onpageshow = functionbody #
onpopstate = functionbody NEW #
User navigated session history.
onresize = functionbody NEW #
Document view was resized.
onstorage = functionbody NEW #
Storage area changed.
onunload = functionbody #
Document is going away.

Additional constraints and admonitions #

Tag omission #

A body element’s start tag may be omitted if the first thing inside the body element is not a space character or a comment, except if the first thing inside the body element is a script or style element.

A body element’s end tag may be omitted if the body element is not immediately followed by a comment and the element is either not empty or its start tag has not been omitted.

Permitted parent elements #


DOM interface #

interface HTMLBodyElement : HTMLElement {
           attribute EventHandler onafterprint;
           attribute EventHandler onbeforeprint;
           attribute EventHandler onbeforeunload;
           attribute EventHandler onblur;
           attribute OnErrorEventHandler onerror;
           attribute EventHandler onfocus;
           attribute EventHandler onhashchange;
           attribute EventHandler onload;
           attribute EventHandler onmessage;
           attribute EventHandler onoffline;
           attribute EventHandler ononline;
           attribute EventHandler onpopstate;
           attribute EventHandler onpagehide;
           attribute EventHandler onpageshow;
           attribute EventHandler onresize;
           attribute EventHandler onscroll;
           attribute EventHandler onstorage;
           attribute EventHandler onunload;

Typical default display properties #

body {
display: block;
margin: 8px; }
body:focus {
outline: none; }