Summary
The HTML <body>
element represents the content of an HTML document. There is 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, {{HTMLElement("script")}} element or {{HTMLElement("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 It must be the second element of an {{HTMLElement("html")}} element.
- DOM interface {{domxref("HTMLBodyElement")}}
- The
<body>
element exposes the {{domxref("HTMLBodyElement")}} interface. - You can access the body element through the {{domxref("document.body")}} attribute.
- The
Attributes
This element includes the global attributes.
Note: Starting in Gecko 7.0 {{geckoRelease("7.0")}},
background
is no longer resolved as a URI; instead, it's treated as a simple string.- {{htmlattrdef("alink")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- Color of text for hyperlinks when selected.
- {{htmlattrdef("background")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- URI of a image to use as a background.
- {{htmlattrdef("bgcolor")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- Background color for the document.
- {{htmlattrdef("bottommargin")}} {{HTMLVersionInline(5)}}
- The margin of the bottom of the body.
- {{htmlattrdef("leftmargin")}} {{HTMLVersionInline(5)}}
- The margin of the left of the body.
- {{htmlattrdef("link")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- Color of text for unvisited hypertext links.
- {{htmlattrdef("onafterprint")}} {{HTMLVersionInline(5)}}
- Function to call after the user has printed the document.
- {{htmlattrdef("onbeforeprint")}} {{HTMLVersionInline(5)}}
- Function to call when the user requests printing of the document.
- {{htmlattrdef("onbeforeunload")}} {{HTMLVersionInline(5)}}
- Function to call when the document is about to be unloaded.
- {{htmlattrdef("onblur")}} {{HTMLVersionInline(5)}}
- Function to call when the document loses focus.
- {{htmlattrdef("onerror")}} {{HTMLVersionInline(5)}}
- Function to call when the document fails to load properly.
- {{htmlattrdef("onfocus")}} {{HTMLVersionInline(5)}}
- Function to call when the document receives focus.
- {{htmlattrdef("onhashchange")}} {{HTMLVersionInline(5)}}
- Function to call when the fragment identifier part (starting with the hash (#) character) of the document's current address has changed.
- {{htmlattrdef("onlanguagechange")}} {{experimental_inline}}
- Function to call when the preferred languages changed.
- {{htmlattrdef("onload")}} {{HTMLVersionInline(5)}}
- Function to call when the document has finished loading.
- {{htmlattrdef("onmessage")}} {{HTMLVersionInline(5)}}
- Function to call when the document has received a message.
- {{htmlattrdef("onoffline")}} {{HTMLVersionInline(5)}}
- Function to call when network communication has failed.
- {{htmlattrdef("ononline")}} {{HTMLVersionInline(5)}}
- Function to call when network communication has been restored.
- {{htmlattrdef("onpopstate")}} {{HTMLVersionInline(5)}}
- Function to call when the user has navigated session history.
- {{htmlattrdef("onredo")}} {{HTMLVersionInline(5)}}
- Function to call when the user has moved forward in undo transaction history.
- {{htmlattrdef("onresize")}} {{HTMLVersionInline(5)}}
- Function to call when the document has been resized.
- {{htmlattrdef("onstorage")}} {{HTMLVersionInline(5)}}
- Function to call when the storage area has changed.
- {{htmlattrdef("onundo")}} {{HTMLVersionInline(5)}}
- Function to call when the user has moved backward in undo transaction history.
- {{htmlattrdef("onunload")}} {{HTMLVersionInline(5)}}
- Function to call when the document is going away.
- {{htmlattrdef("rightmargin")}} {{HTMLVersionInline(5)}}
- The margin of the right of the body.
- {{htmlattrdef("text")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- Foreground color of text.
- {{htmlattrdef("topmargin")}} {{HTMLVersionInline(5)}}
- The margin of the top of the body.
- {{htmlattrdef("vlink")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
- Color of text for visited hypertext links.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', 'sections.html#the-body-element', '<body>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'sections.html#the-body-element', '<body>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'struct/global.html#h-7.5.1', '<body>')}} | {{Spec2('HTML4.01')}} |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
onlanguagechange |
{{CompatUnknown}} | {{CompatGeckoDesktop("32")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
onlanguagechange |
{{CompatUnknown}} | {{CompatGeckoMobile("32")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
See also
- {{HTMLElement("html")}}
- {{HTMLElement("head")}}
{{HTMLRef}}