The <body> HTML element represents the content of an HTML document. There can be only one <body> element in a document.
<body>: The Document Body element
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Attributes
This element includes the global attributes.
-
alinkDeprecated -
Color of text for hyperlinks when selected. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:activepseudo-class instead. -
backgroundDeprecated -
URI of an image to use as a background. Do not use this attribute! Use the CSS
backgroundproperty on the element instead. -
bgcolorDeprecated -
Background color for the document. Do not use this attribute! Use the CSS
background-colorproperty on the element instead. -
bottommarginDeprecated -
The margin of the bottom of the body. Do not use this attribute! Use the CSS
margin-bottomproperty on the element instead. -
leftmarginDeprecated -
The margin of the left of the body. Do not use this attribute! Use the CSS
margin-leftproperty on the element instead. -
linkDeprecated -
Color of text for unvisited hypertext links. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:linkpseudo-class instead. onafterprint-
Function to call after the user has printed the document.
onbeforeprint-
Function to call when the user requests printing of the document.
onbeforeunload-
Function to call when the document is about to be unloaded.
onblur-
Function to call when the document loses focus.
onerror-
Function to call when the document fails to load properly.
onfocus-
Function to call when the document receives focus.
onhashchange-
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-
Function to call when the document has finished loading.
onmessage-
Function to call when the document has received a message.
onoffline-
Function to call when network communication has failed.
ononline-
Function to call when network communication has been restored.
onpopstate-
Function to call when the user has navigated session history.
onresize-
Function to call when the document has been resized.
onstorage-
Function to call when the storage area has changed.
onunload-
Function to call when the document is going away.
-
rightmarginDeprecated -
The margin of the right of the body. Do not use this attribute! Use the CSS
margin-rightproperty on the element instead. -
textDeprecated -
Foreground color of text. Do not use this attribute! Use CSS
colorproperty on the element instead. -
topmarginDeprecated -
The margin of the top of the body. Do not use this attribute! Use the CSS
margin-topproperty on the element instead. -
vlinkDeprecated -
Color of text for visited hypertext links. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:visitedpseudo-class instead.
Examples
<html lang="en"> <head> <title>Document title</title> </head> <body> <p> The <code><body></code> HTML element represents the content of an HTML document. There can be only one <code><body></code> element in a document. </p> </body> </html>
Result
Technical summary
| Content categories | None. |
|---|---|
| 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 parents | It must be the second element of an <html> element. |
| Implicit ARIA role | generic |
| Permitted ARIA roles | No role permitted |
| DOM interface |
HTMLBodyElement
|
Specifications
| Specification |
|---|
| HTML Standard # the-body-element |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | ||
body |
1 | 12 | 1 | 15 | 1 | 18 | 4 | 14 | 1 | 1.0 | 4.4 | |
alink |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
background |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
bgcolor |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
bottommargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | |
leftmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | |
link |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
rightmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | |
text |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
topmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | |
vlink |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | |
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body