Revision 340881 of <body>

  • Revision slug: HTML/Element/body
  • Revision title: <body>
  • Revision id: 340881
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment Broken Links.

Revision Content

Summary

The HTML <body> element represents the main 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")}}

Attributes

Like all HTML elements, this element has 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("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("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("text")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
Foreground color of text.
{{htmlattrdef("vlink")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.
Color of text for visited hypertext links.

DOM Interface

  • The <body> element exposes the {{domxref("HTMLBodyElement")}} interface.
  • You can access the body element through the {{domxref("document.body")}} attribute.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'sections.html#the-body-element', '<body>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'the-body-element.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}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

See also

  • {{HTMLElement("html")}}
  • {{HTMLElement("head")}}
{{HTML:Element_Navigation}}

Revision Source

<h2 id="Summary">Summary</h2>
<p>The <strong>HTML <code>&lt;body&gt;</code> element</strong> represents the main content of an HTML&nbsp;document. There is only one <code>&lt;body&gt;</code> element in a document.</p>
<ul class="htmlelt">
  <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/Sections_and_Outlines_of_an_HTML5_document#Sectioning_root" title="Sections and Outlines of an HTML5 document#Sectioning root">Sectioning root</a>.</li>
  <li><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content_categories#Flow_content">Flow content</a>.</li>
  <li><dfn>Tag omission</dfn> 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.</li>
  <li><dfn>Permitted parent elements</dfn> It must be the second element of an {{HTMLElement("html")}} element.</li>
  <li><dfn>DOM interface</dfn> {{domxref("HTMLBodyElement")}}</li>
</ul>
<h2 id="Attributes">Attributes</h2>
<p>Like all HTML elements, this element has the <a href="/en-US/docs/HTML/Global_attributes" title="HTML/Global attributes">global attributes</a>.</p>
<div class="note">
  <strong>Note:</strong> Starting in Gecko 7.0 {{geckoRelease("7.0")}}, <code>background</code> is no longer resolved as a URI; instead, it's treated as a simple string.</div>
<dl>
  <dt>
    {{htmlattrdef("alink")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    Color of text for hyperlinks when selected.</dd>
  <dt>
    {{htmlattrdef("background")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    URI of a image to use as a background.</dd>
  <dt>
    {{htmlattrdef("bgcolor")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    Background color for the document.</dd>
  <dt>
    {{htmlattrdef("link")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    Color of text for unvisited hypertext links.</dd>
  <dt>
    {{htmlattrdef("onafterprint")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call after the user has printed the document.</dd>
  <dt>
    {{htmlattrdef("onbeforeprint")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the user requests printing of the document.</dd>
  <dt>
    {{htmlattrdef("onbeforeunload")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document is about to be unloaded.</dd>
  <dt>
    {{htmlattrdef("onblur")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document loses focus.</dd>
  <dt>
    {{htmlattrdef("onerror")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document fails to load properly.</dd>
  <dt>
    {{htmlattrdef("onfocus")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document receives focus.</dd>
  <dt>
    {{htmlattrdef("onhashchange")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the fragment identifier part (starting with the hash (#) character) of the document's current address has changed.</dd>
  <dt>
    {{htmlattrdef("onload")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document has finished loading.</dd>
  <dt>
    {{htmlattrdef("onmessage")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document has received a message.</dd>
  <dt>
    {{htmlattrdef("onoffline")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when network communication has failed.</dd>
  <dt>
    {{htmlattrdef("ononline")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when network communication has been restored.</dd>
  <dt>
    {{htmlattrdef("onpopstate")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the user has navigated session history.</dd>
  <dt>
    {{htmlattrdef("onredo")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the user has moved forward in undo transaction history.</dd>
  <dt>
    {{htmlattrdef("onresize")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document has been resized.</dd>
  <dt>
    {{htmlattrdef("onstorage")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the storage area has changed.</dd>
  <dt>
    {{htmlattrdef("onundo")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the user has moved backward in undo transaction history.</dd>
  <dt>
    {{htmlattrdef("onunload")}} {{HTMLVersionInline(5)}}</dt>
  <dd>
    Function to call when the document is going away.</dd>
  <dt>
    {{htmlattrdef("text")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    Foreground color of text.</dd>
  <dt>
    {{htmlattrdef("vlink")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}; use CSS instead.</dt>
  <dd>
    Color of text for visited hypertext links.</dd>
</dl>
<h2 id="DOM_Interface">DOM Interface</h2>
<ul>
  <li>The <code>&lt;body&gt;</code> element exposes the {{domxref("HTMLBodyElement")}} interface.</li>
  <li>You can access the body element through the {{domxref("document.body")}} attribute.</li>
</ul>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('HTML WHATWG', 'sections.html#the-body-element', '&lt;body&gt;')}}</td>
      <td>{{Spec2('HTML WHATWG')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('HTML5 W3C', 'the-body-element.html#the-body-element', '&lt;body&gt;')}}</td>
      <td>{{Spec2('HTML5 W3C')}}</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>{{SpecName('HTML4.01', 'struct/global.html#h-7.5.1', '&lt;body&gt;')}}</td>
      <td>{{Spec2('HTML4.01')}}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{HTMLElement("html")}}</li>
  <li>{{HTMLElement("head")}}</li>
</ul>
<div>
  {{HTML:Element_Navigation}}</div>
Revert to this revision