HTML: The Markup Language

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.
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 {
  [TreatNonCallableAsNull] attribute Function? onafterprint;
  [TreatNonCallableAsNull] attribute Function? onbeforeprint;
  [TreatNonCallableAsNull] attribute Function? onbeforeunload;
  [TreatNonCallableAsNull] attribute Function? onblur;
  [TreatNonCallableAsNull] attribute Function? onerror;
  [TreatNonCallableAsNull] attribute Function? onfocus;
  [TreatNonCallableAsNull] attribute Function? onhashchange;
  [TreatNonCallableAsNull] attribute Function? onload;
  [TreatNonCallableAsNull] attribute Function? onmessage;
  [TreatNonCallableAsNull] attribute Function? onoffline;
  [TreatNonCallableAsNull] attribute Function? ononline;
  [TreatNonCallableAsNull] attribute Function? onpopstate;
  [TreatNonCallableAsNull] attribute Function? onpagehide;
  [TreatNonCallableAsNull] attribute Function? onpageshow;
  [TreatNonCallableAsNull] attribute Function? onresize;
  [TreatNonCallableAsNull] attribute Function? onscroll;
  [TreatNonCallableAsNull] attribute Function? onstorage;
  [TreatNonCallableAsNull] attribute Function? onunload;

Typical default display properties #

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