Summary
The HTML Body (<body>) element represents the main content of an HTML document. There is only one <body> element in a document.
Usage Context
| Content category | 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 | <html> |
| Normative document | HTML5, section 4.4; HTML 4.01, section 7.5.1 |
Attributes
Like all HTML elements, this element has the global attributes.
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.alinkDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- Color of text for hyperlinks when selected.
backgroundDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- URI of a image to use as a background.
bgcolorDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- Background color for the document.
linkDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- Color of text for unvisited hypertext links.
onafterprintHTML5- Function to call after the user has printed the document.
onbeforeprintHTML5- Function to call when the user requests printing of the document.
onbeforeunloadHTML5- Function to call when the document is about to be unloaded.
onblurHTML5- Function to call when the document loses focus.
onerrorHTML5- Function to call when the document fails to load properly.
onfocusHTML5- Function to call when the document receives focus.
onhashchangeHTML5- Function to call when the fragment identifier part (starting with the hash (#) character) of the document's current address has changed.
onloadHTML5- Function to call when the document has finished loading.
onmessageHTML5- Function to call when the document has received a message.
onofflineHTML5- Function to call when network communication has failed.
ononlineHTML5- Function to call when network communication has been restored.
onpopstateHTML5- Function to call when the user has navigated session history.
onredoHTML5- Function to call when the user has moved forward in undo transaction history.
onresizeHTML5- Function to call when the document has been resized.
onstorageHTML5- Function to call when the storage area has changed.
onundoHTML5- Function to call when the user has moved backward in undo transaction history.
onunloadHTML5- Function to call when the document is going away.
textDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- Foreground color of text.
vlinkDeprecated since HTML4.01, Obsolete since HTML5; use CSS instead.- Color of text for visited hypertext links.
DOM Interface
- The
<body>element exposes theHTMLBodyElementinterface. - You can access the body element through the
document.bodyattribute.
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 1.0 | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |


Mozilla Developer Network