body

FilterElements

<body> ... </body>

The body of a document contains the document’s content. Content may be presented visually (as in a graphical browser window) or aurally (by a screen reader). There may only be one body element in a document. In HTML documents, it is optional; in XHTML it is required.

Notes

All of the presentational attributes for the body are deprecated in (X)HTML and have been dropped from HTML5 in favor of style sheet controls.

Start/End Tags

HTML 4.01 and 5: Optional/Optional; XHTML: Required/Required

Specifications

  • HTML 4.01
  • HTML5

background=

Values: URL
Deprecated. Not in HTML5. Provides the location of a graphic file to be used as a tiling graphic in the background of the document.

bgcolor=

Values: #rrggbb or color name
Deprecated. Not in HTML5. Sets the color of the background for the document.

text=

Values: #rrggbb or color name
Deprecated. Not in HTML5. Sets the default color for all the nonhyperlink and unstyled text in the document.

HTML 4.01 <body> Events

onload
Occurs when the document loads
onunload
Occurs when the user leaves the document

HTML5 <body> Events

The following events are triggered on the Window object when applied to the body element:

onafterprint
Occurs after the document is printed
onbeforeprint
Occurs before the document is printed
onbeforeonload
Occurs before the document loads
onblur
Occurs when the window loses focus
onerror
Occurs when an error occurs
onfocus
Occurs when the window gets focus
onhaschange
Occurs when the document has change
onload
Occurs when the document loads
onmessage
Occus when a message is triggered
onoffline
Occurs when the document goes offline
ononline
Occurs when the document comes online
onpagehide
Occurs when the window displaying the document is hidden
onpageshow
Occurs when the window displaying the document becomes visible
onpopstate
Occurs when the window's history changes
onredo
Occurs when the document performs a redo
onresize
Occurs when the window is resized
onstorage
Occurs when a storage event is targeted (using DOM storage)
onundo
Occurs when a document performs an undo
onunload
Occurs when the user leaves the document
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/HTML4.01/strict.dtd">
<html>
  <head>
    <title>Document Title</title>
   </head>
  <body>
    <p>Content of document ... </p>
  </body>
</html>

Rendered Example

body gives a document structure only. Content within the document’s body can be styled with CSS.