This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The <body> HTML element represents the content of an HTML document. There can be only one <body> element in a document.
This element includes the global attributes, event attributes, and deprecated attributes:
Note: Each of the below event attribute names is linked to its equivalent Window interface event. You can listen to these events using addEventListener() instead of adding the oneventname attribute to the <body> element.
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.
onmessageerrorFunction to call when the document has received a message that cannot be deserialized.
onofflineFunction to call when network communication has failed.
ononlineFunction to call when network communication has been restored.
onpageswapFunction to call when you navigate across documents, when the previous document is about to unload.
onpagehideFunction to call when the browser hides the current page in the process of presenting a different page from the session's history.
onpagerevealFunction to call when a document is first rendered, either when loading a fresh document from the network or activating a document.
onpageshowFunction to call when the browser displays the window's document due to navigation.
onpopstateFunction to call when the user has navigated session history.
onresizeFunction to call when the document has been resized.
onrejectionhandledFunction to call when a JavaScript Promise is handled late.
onstorageFunction to call when the storage area has changed.
onunhandledrejectionFunction to call when a JavaScript Promise that has no rejection handler is rejected.
onunloadFunction to call when the document is going away.
Warning: Do not use these deprecated attributes; opt for the CSS alternatives listed with each deprecated attribute instead.
alink Deprecated Color of text for hyperlinks when selected. Use the CSS color property in conjunction with the :active and :focus pseudo-classes instead.
background Deprecated URI of an image to use as a background. Use the CSS background-image property instead.
bgcolor Deprecated Background color for the document. Use the CSS background-color property instead.
bottommargin Deprecated The margin of the bottom of the body. Use the CSS margin-bottom property (or the logical margin-block-end property) instead.
leftmargin Deprecated The margin of the left of the body. Use the CSS margin-left property (or the logical margin-inline-start property) instead.
link Deprecated Color of text for unvisited hypertext links. Use the CSS color property in conjunction with the :link pseudo-class instead.
rightmargin Deprecated The margin of the right of the body. Use the CSS margin-right property or the logical margin-inline-end property) instead.
text Deprecated Foreground color of text. Use the CSS color property instead.
topmargin Deprecated The margin of the top of the body. Use the CSS margin-top property (or the logical margin-block-start property) instead.
vlink Deprecated Color of text for visited hypertext links. Use the CSS color property in conjunction with the :visited pseudo-class instead.
<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>
| 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
|
| Specification |
|---|
| HTML> # the-body-element> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
body |
1 | 12 | 1 | 15 | 1 | 18 | 4 | 14 | 1 | 1.0 | 4.4 | 1 |
alink |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
background |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
bgcolor |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
bottommargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox for Android 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
leftmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox for Android 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
link |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
rightmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox for Android 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
text |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
topmargin |
1 | 79 | 35Before Firefox 35, it was supported in Quirks Mode only. |
15 | ≤4 | 18 | 35Before Firefox for Android 35, it was supported in Quirks Mode only. |
14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
vlink |
1 | 12 | 1 | 15 | ≤4 | 18 | 4 | 14 | ≤3.2 | 1.0 | 4.4 | ≤3.2 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/body