<body>

  • Revision slug: HTML/Element/body
  • Revision title: body
  • Revision id: 3511
  • Created:
  • Creator: jswisher
  • Is current revision? No
  • Comment 2 words added

Revision Content

The HTML Body (<body>) element represents the main content of an HTML document. There is only one <body> element in a document.

Usage Context

Content category 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 {{ HTMLElement("html") }}
Normative document HTML5, section 4.4; HTML 4.01, section 7.5.1

Attributes

Like all HTML elements, this element has the global attributes.

{{ htmlattrdef("alink") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Color of text for hyperlinks when selected.
{{ htmlattrdef("background") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. URI of a image to use as a background.
{{ htmlattrdef("bgcolor") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Background color for the document.
{{ htmlattrdef("link") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; 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") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Foreground color of text.
{{ htmlattrdef("vlink") }}
{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Color of text for visited hypertext links.

DOM Interface

See Also

  • {{ HTMLElement("html") }}
  • {{ HTMLElement("head") }}

{{ HTML:Element_Navigation() }}

Revision Source

<p>The HTML Body (<code>&lt;body&gt;</code>) element represents the main content of an HTML document. There is only one <code>&lt;body&gt;</code> element in a document.</p>
<h2>Usage Context</h2>
<table class="standard-table"> <tbody> <tr> <td>Content category</td> <td><a href="/en/Sections_and_Outlines_of_an_HTML5_document#sectioning_root" title="en/Sections and Outlines of an HTML5 document#sectioning root">Sectioning root</a>.</td> </tr> <tr> <td>Permitted content</td> <td><a href="/en/HTML/Content_categories#Flow_content" title="en/HTML/Content categories#Flow content">Flow content</a>.</td> </tr> <tr> <td>Tag omission</td> <td>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.</td> </tr> <tr> <td>Permitted parent elements</td> <td>{{ HTMLElement("html") }}</td> </tr> <tr> <td>Normative document</td> <td><a class=" external" href="http://www.w3.org/TR/html5/sections.html#the-body-element-0" title="http://www.w3.org/TR/html5/sections.html#the-body-element-0">HTML5, section 4.4</a>; <a class=" external" href="http://www.w3.org/TR/html401/struct/global.html#h-7.5.1" title="http://www.w3.org/TR/html401/struct/global.html#h-7.5.1">HTML 4.01, section 7.5.1</a></td> </tr> </tbody>
</table>
<h2>Attributes</h2>
<p>Like all HTML elements, this element has the <a href="/en/HTML/Global_attributes" title="en/HTML/Global attributes">global attributes</a>.</p>
<dl> <dt>{{ htmlattrdef("alink") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Color of text for hyperlinks when selected.</dd> <dt>{{ htmlattrdef("background") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. URI of a image to use as a background.</dd> <dt>{{ htmlattrdef("bgcolor") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Background color for the document.</dd> <dt>{{ htmlattrdef("link") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. 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> </dt><dt>{{ htmlattrdef("onbeforeunload") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document is about to be unloaded.</dd> <dt> </dt><dt>{{ htmlattrdef("onblur") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document loses focus.</dd> <dt> </dt><dt>{{ htmlattrdef("onerror") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document fails to load properly.</dd> <dt> </dt><dt>{{ htmlattrdef("onfocus") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document receives focus.</dd> <dt> </dt><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> </dt><dt>{{ htmlattrdef("onload") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document has finished loading.</dd> <dt> </dt><dt>{{ htmlattrdef("onmessage") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document has received a message.</dd> <dt> </dt><dt>{{ htmlattrdef("onoffline") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when network communication has failed.</dd> <dt> </dt><dt>{{ htmlattrdef("ononline") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when network communication has been restored.</dd> <dt> </dt><dt>{{ htmlattrdef("onpopstate") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the user has navigated session history.</dd> <dt> </dt><dt>{{ htmlattrdef("onredo") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the user has moved forward in undo transaction history.</dd> <dt> </dt><dt>{{ htmlattrdef("onresize") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document has been resized.</dd> <dt> </dt><dt>{{ htmlattrdef("onstorage") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the storage area has changed.</dd> <dt> </dt><dt>{{ htmlattrdef("onundo") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the user has moved backward in undo transaction history.</dd> <dt> </dt><dt>{{ htmlattrdef("onunload") }} {{ HTMLVersionInline("5") }}</dt> <dd>Function to call when the document is going away.</dd> <dt>{{ htmlattrdef("text") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Foreground color of text.</dd> <dt>{{ htmlattrdef("vlink") }}</dt> <dd>{{ deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}; use CSS instead. Color of text for visited hypertext links.</dd>
</dl>
<h2>DOM Interface</h2>
<ul> <li>The <code>&lt;body&gt;</code> element exposes the <a href="/en/DOM/HTMLBodyElement" title="en/DOM/HTMLBodyElement">HTMLBodyElement</a> interface.</li> <li>You can access the body element through the <a href="/en/DOM/document.body" title="en/DOM/document.body">document.body</a> attribute.</li>
</ul>
<h2>See Also</h2>
<ul> <li>{{ HTMLElement("html") }}</li> <li>{{ HTMLElement("head") }}</li>
</ul>
<p>{{ HTML:Element_Navigation() }}</p>
Revert to this revision