<body>: The Document Body element #
::: section-content
The <body>
HTML element represents the content of an HTML
document. There can be only one <body> element in a document.
| 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
|
Attributes #
::: section-content This element includes the global attributes.
alink[Deprecated]{.visually-hidden}Color of text for hyperlinks when selected. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:activepseudo-class instead.background[Deprecated]{.visually-hidden}URI of an image to use as a background. Do not use this attribute! Use the CSS
backgroundproperty on the element instead.bgcolor[Deprecated]{.visually-hidden}Background color for the document. Do not use this attribute! Use the CSS
background-colorproperty on the element instead.bottommargin[Deprecated]{.visually-hidden}The margin of the bottom of the body. Do not use this attribute! Use the CSS
margin-bottomproperty on the element instead.leftmargin[Deprecated]{.visually-hidden}The margin of the left of the body. Do not use this attribute! Use the CSS
margin-leftproperty on the element instead.link[Deprecated]{.visually-hidden}Color of text for unvisited hypertext links. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:linkpseudo-class instead.onafterprintFunction to call after the user has printed the document.
onbeforeprintFunction to call when the user requests printing of the document.
onbeforeunloadFunction to call when the document is about to be unloaded.
onblurFunction to call when the document loses focus.
onerrorFunction to call when the document fails to load properly.
onfocusFunction to call when the document receives focus.
onhashchangeFunction to call when the fragment identifier part (starting with the hash (
'#') character) of the document's current address has changed.onlanguagechangeFunction to call when the preferred languages changed.
onloadFunction to call when the document has finished loading.
onmessageFunction to call when the document has received a message.
onofflineFunction to call when network communication has failed.
ononlineFunction to call when network communication has been restored.
onpopstateFunction to call when the user has navigated session history.
onredoFunction to call when the user has moved forward in undo transaction history.
onresizeFunction to call when the document has been resized.
onstorageFunction to call when the storage area has changed.
onundoFunction to call when the user has moved backward in undo transaction history.
onunloadFunction to call when the document is going away.
rightmargin[Deprecated]{.visually-hidden}The margin of the right of the body. Do not use this attribute! Use the CSS
margin-rightproperty on the element instead.text[Deprecated]{.visually-hidden}Foreground color of text. Do not use this attribute! Use CSS
colorproperty on the element instead.topmargin[Deprecated]{.visually-hidden}The margin of the top of the body. Do not use this attribute! Use the CSS
margin-topproperty on the element instead.vlink[Deprecated]{.visually-hidden}Color of text for visited hypertext links. Do not use this attribute! Use the CSS
colorproperty in conjunction with the:visitedpseudo-class instead. :::
Examples #
::: section-content ::: code-example [html]{.language-name}
<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 #
::: section-content ::: {#sect1 .code-example} ::: iframe ::: ::: :::
Specifications #
::: _table #
Specification #
HTML Standard
[#
the-body-element]{.small}
:::
Browser compatibility #
::: _table #
Desktop Mobile
Chrome Edge Firefox Internet Opera Safari WebView Chrome Firefox for Opera Safari Samsung
Explorer Android Android Android Android on IOS Internet
body 1 12 1 Yes 15 1 4.4 18 4 14 1 1.0
alink 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
background 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
bgcolor 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
bottommargin 1 79 35 No 15 ≤4 4.4 18 35 14 ≤3.2 1.0
Before Before
Firefox 35, Firefox 35,
it was it was
supported supported
in Quirks in Quirks
Mode only. Mode only.
leftmargin 1 79 35 No 15 ≤4 4.4 18 35 14 ≤3.2 1.0
Before Before
Firefox 35, Firefox 35,
it was it was
supported supported
in Quirks in Quirks
Mode only. Mode only.
link 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
rightmargin 1 79 35 No 15 ≤4 4.4 18 35 14 ≤3.2 1.0
Before Before
Firefox 35, Firefox 35,
it was it was
supported supported
in Quirks in Quirks
Mode only. Mode only.
text 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
topmargin 1 79 35 No 15 ≤4 4.4 18 35 14 ≤3.2 1.0
Before Before
Firefox 35, Firefox 35,
it was it was
supported supported
in Quirks in Quirks
Mode only. Mode only.
vlink 1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
#
:::
See also #
::: section-content
::: _attribution
© 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{._attribution-link}
:::