Summary

The HTML Body Element (<body>) represents the content of an HTML document. There can be only one <body> element in a document.

  • Content categories Sectioning root.
  • Permitted content Flow content.
  • Tag omission The start tag may be omitted if the first thing inside it is not a space character, comment, <script> element or <style> element. The end tag may be omitted if the body element has contents or has a start tag, and is not immediately followed by a comment.
  • Permitted parent elements It must be the second element of an <html> element.
  • DOM interface HTMLBodyElement

Attributes

This element includes the global attributes.

alink
Color of text for hyperlinks when selected. This method is non-conforming, use CSS color property in conjunction with the :active pseudo-class instead.
background
URI of a image to use as a background. This method is non-conforming, use CSS background property on the element instead.
Note: Starting in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), background is no longer resolved as a URI; instead, it's treated as a simple string.
bgcolor
Background color for the document. This method is non-conforming, use CSS background-color property on the element instead.
bottommargin
The margin of the bottom of the body. This method is non-conforming, use CSS margin-bottom property on the element instead.
leftmargin
The margin of the left of the body. This method is non-conforming, use CSS margin-left property on the element instead.
link
Color of text for unvisited hypertext links. This method is non-conforming, use CSS color property in conjunction with the :link pseudo-class instead.
onafterprint HTML5
Function to call after the user has printed the document.
onbeforeprint HTML5
Function to call when the user requests printing of the document.
onbeforeunload HTML5
Function to call when the document is about to be unloaded.
onblur HTML5
Function to call when the document loses focus.
onerror HTML5
Function to call when the document fails to load properly.
onfocus HTML5
Function to call when the document receives focus.
onhashchange HTML5
Function to call when the fragment identifier part (starting with the hash ('#') character) of the document's current address has changed.
onlanguagechange
Function to call when the preferred languages changed.
onload HTML5
Function to call when the document has finished loading.
onmessage HTML5
Function to call when the document has received a message.
onoffline HTML5
Function to call when network communication has failed.
ononline HTML5
Function to call when network communication has been restored.
onpopstate HTML5
Function to call when the user has navigated session history.
onredo HTML5
Function to call when the user has moved forward in undo transaction history.
onresize HTML5
Function to call when the document has been resized.
onstorage HTML5
Function to call when the storage area has changed.
onundo HTML5
Function to call when the user has moved backward in undo transaction history.
onunload HTML5
Function to call when the document is going away.
rightmargin
The margin of the right of the body. This method is non-conforming, use CSS margin-right property on the element instead.
text
Foreground color of text. This method is non-conforming, use CSS color property on the element instead.
topmargin
The margin of the top of the body. This method is non-conforming, use CSS margin-top property on the element instead.
vlink
Color of text for visited hypertext links. This method is non-conforming, use CSS color property in conjunction with the :visited pseudo-class instead.

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of '<body>' in that specification.
Living Standard Changed the list of non-conforming features.
HTML5
The definition of '<body>' in that specification.
Recommendation Obsoleted the formerly deprecated attributes. Defined the behavior of the non-conforming and never standardized margintop, marginleft, marginright and marginbottom.
HTML 4.01 Specification
The definition of '<body>' in that specification.
Recommendation Deprecated the alink, background, bgcolor, link, text and vlink attributes.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 (Yes) (Yes) (Yes) (Yes)
onlanguagechange ? 32 (32) ? ? ?
bottommargin, leftmargin, rightmargin, topmargin (Yes) 35 (35) [1] ? ? ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
onlanguagechange ? 32.0 (32) ? ? ?
bottommargin, leftmargin, rightmargin, topmargin (Yes) 35.0 (35) [1] ? ? ?

[1] Was supported before this in Quirk Mode only.

See also

Document Tags and Contributors

Last updated by: Sheppy,