W3cubDocs

/HTML

<body>

The <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 parents It must be the second element of an <html> element.
Implicit ARIA role document
Permitted ARIA roles No role permitted
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.
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
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.
onredo
Function to call when the user has moved forward in undo transaction history.
onresize
Function to call when the document has been resized.
onstorage
Function to call when the storage area has changed.
onundo
Function to call when the user has moved backward in undo transaction history.
onunload
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.

Example

<html>
  <head>
    <title>Document title</title>
  </head>
  <body>
    <p>This is a paragraph</p>
  </body>
</html>

Specifications

Specification Status Comment
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 topmargin, leftmargin, rightmargin and bottommargin. Added the on* attributes.
HTML 4.01 Specification
The definition of '<body>' in that specification.
Recommendation Deprecated the alink, background, bgcolor, link, text and vlink attributes.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
body 1 12 1 Yes Yes Yes
alink 1 12 1 Yes Yes Yes
background 1 12 1 Yes Yes Yes
bgcolor 1 12 1 Yes Yes Yes
bottommargin Yes 79 35
35
Before Firefox 35, it was supported in Quirks Mode only.
No Yes ?
leftmargin Yes 79 35
35
Before Firefox 35, it was supported in Quirks Mode only.
No Yes ?
link 1 12 1 Yes Yes Yes
onafterprint 1 12 1 Yes Yes 13
onbeforeprint 1 12 1 Yes Yes 13
onbeforeunload 1 12 1 Yes Yes Yes
onblur 1 12 1 Yes Yes Yes
onerror 1 12 1 Yes Yes Yes
onfocus 1 12 1 Yes Yes Yes
onhashchange 1 12 1 Yes Yes Yes
onlanguagechange ? ? 32 No ? ?
onload 1 12 1 Yes Yes Yes
onmessage 1 12 1 Yes Yes Yes
onoffline 1 12 1 Yes Yes Yes
ononline 1 12 1 Yes Yes Yes
onpopstate 1 12 1 Yes Yes Yes
onredo 1 12 1 Yes Yes Yes
onresize 1 12 1 Yes Yes Yes
onstorage 1 12 1 Yes Yes Yes
onundo 1 12 1 Yes Yes Yes
onunload 1 12 1 Yes Yes Yes
rightmargin Yes 79 35
35
Before Firefox 35, it was supported in Quirks Mode only.
No Yes ?
text 1 12 1 Yes Yes Yes
topmargin Yes 79 35
35
Before Firefox 35, it was supported in Quirks Mode only.
No Yes ?
vlink 1 12 1 Yes Yes Yes
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
body Yes 18 4 Yes Yes 1.0
alink Yes 18 4 Yes Yes 1.0
background Yes 18 4 Yes Yes 1.0
bgcolor Yes 18 4 Yes Yes 1.0
bottommargin Yes Yes 35
35
Before Firefox 35, it was supported in Quirks Mode only.
Yes ? Yes
leftmargin Yes Yes 35
35
Before Firefox 35, it was supported in Quirks Mode only.
Yes ? Yes
link Yes 18 4 Yes Yes 1.0
onafterprint Yes 18 4 Yes 13 1.0
onbeforeprint Yes 18 4 Yes 13 1.0
onbeforeunload Yes 18 4 Yes Yes 1.0
onblur Yes 18 4 Yes Yes 1.0
onerror Yes 18 4 Yes Yes 1.0
onfocus Yes 18 4 Yes Yes 1.0
onhashchange Yes 18 4 Yes Yes 1.0
onlanguagechange ? ? 32 ? ? ?
onload Yes 18 4 Yes Yes 1.0
onmessage Yes 18 4 Yes Yes 1.0
onoffline Yes 18 4 Yes Yes 1.0
ononline Yes 18 4 Yes Yes 1.0
onpopstate Yes 18 4 Yes Yes 1.0
onredo Yes 18 4 Yes Yes 1.0
onresize Yes 18 4 Yes Yes 1.0
onstorage Yes 18 4 Yes Yes 1.0
onundo Yes 18 4 Yes Yes 1.0
onunload Yes 18 4 Yes Yes 1.0
rightmargin Yes Yes 35
35
Before Firefox 35, it was supported in Quirks Mode only.
Yes ? Yes
text Yes 18 4 Yes Yes 1.0
topmargin Yes Yes 35
35
Before Firefox 35, it was supported in Quirks Mode only.
Yes ? Yes
vlink Yes 18 4 Yes Yes 1.0

See also

© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body