Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

BODY - document body

Purpose

The basic structure of an HTML document always consists of a head and a body. It is not necessary to explicitly enclose the body into a BODY element, but by doing so one can specify attributes which affect the document as a whole (e.g. by setting background image or color).

Typical rendering

Using an explicit BODY element does not affect the document rendering, unless the element contains attributes.

Basic syntax

<BODY>document body</BODY>

Possible attributes (Not in HTML 2.0!)

attribute name possible values meaning
BGCOLOR color specification background color for the document
TEXT color specification color for the text of the document
LINK color specification color for unvisited hypertext links
VLINK color specification color for visited hypertext links
ALINK color specification color for active hypertext links; used to stroke the text for a link at the moment the user selects (e.g. clicks on) the link
BACKGROUND URL URL for an image to be used to tile the background.

All of these attributes are deprecated in HTML 4.0

Allowed context

The HTML element, which can be either implicit or explicit. Only one BODY element is allowed in a document, and it must appear after the document head (which can be implicit or explicit).

Contents

Headings, text elements, block elements, and ADDRESS elements.

In HTML 4.0 Strict, text elements may not occur directly within a BODY element but must be enclosed into e.g. a P element.

Examples

Example BODY-1.html:

<BODY>
<H1>Sample document</H1>
<P>
This is just a trivial sample document. Its body contains first
a heading, then a paragraph, and nothing else.
</P>
</BODY>

Example BODY-2.html:

<BODY
BGCOLOR=AQUA
TEXT="#848484"
LINK=RED
VLINK=PURPLE
ALINK=GREEN
>
<H1>Sample document</H1>
<P>
This is also a trivial sample document. Its body contains first
a heading, then a paragraph, and then a paragraph containing a link.
However, the BODY element uses attributes to affect the
visual rendering.
</P>
<P>
This document was written by
<A HREF="../">Jukka Korpela</A>.
</P>
</BODY>

Example BODY-3.html:

<BODY
TEXT=BLUE
LINK=RED
VLINK=BLUE
ALINK=PINK
BGCOLOR=WHITE
BACKGROUND="wave.gif"
>
<H1>Sample document</H1>
<P>
This document contains first
a heading, then a paragraph, and then a paragraph containing a link.
However, the BODY element uses attributes to affect the
visual rendering, including a background image.
</P>
<P>
This document was written by
<A HREF="../">Jukka Korpela</A>.
</P>
</BODY>

Notes

Only one BODY element is allowed in a document.

Be careful when playing with background images and colors. What looks cool on your screen might be disgusting on some other (or in someone else's opinion).

If you set some of the attributes BGCOLOR, TEXT, LINK, VLINK and ALINK, set them all. Otherwise e.g. your specified background color might coincide with user's default color for text. (See discussion of background in the Frequently Encountered Problems document by WDG.

Select the text color so that it works together with the background color or the colors of the background image. For instance, red on green can cause serious problems, because a significant number of people have difficulties in distinguishing them.

The text color can be affected locally by FONT elements with COLOR attribute. Background color cannot be set locally in HTML 3.2; if you want to use different backgrounds, you have to write separate HTML files (or use style sheets).

You can set both BGCOLOR and BACKGROUND. If you do, browsers typically give preference to BACKGROUND, but if the background image cannot be loaded, BGCOLOR is used.

For more information about backgrounds, see The background FAQ (though it is rather old and dusty).



Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.