fbe University of New South Wales Sydney Australia UNSW
Faculty of the Built Environment search
HTML Reference
Body Tag

The body tag surrounds the body of a HTML document. The start tag <body> is placed after the end header tag </head>, and the end tag </body> is placed at the bottom of the document in the "file footer" (see below). Note that there can only be one body tag in a HTML file (some older browsers allow multiple body tags but this is not correct HTML).

Netscape has extended the body tag to provide a means of setting various colour attributes, and to set an image as the background. The possible options that can be added to the body tag are listed below. Each of the attributes have default values that would be used if the attribute is not set. These attributes must be included inside the body tag:

Attribute Notes Syntax
Background
Image
Specifies an image to be used as a background. The image would normally be small, and tileable. When the image is displayed, it is repeated as many times as necessary to cover the background of the browser screen <body background=URL>
Background
Colour
Sets the background to a particular colour. <body bgcolor=colour>
Text
Colour
Sets the colour of foreground (text) colour. <body text=colour>
Link
Colour
Sets the colour used for hyper-links. <body link=colour>
Colour of
Visited Links
Sets the colour used for visited hyper-links. <body vlink=colour>
Colour of
Active Links
Sets the colour used for active hyper-links. <body alink=colour>
Colour
In the examples above, "colour" refers to a red-green-blue hexadecimal triple! Hexadecimal Colour Numbers, are written as: "#rrggbb", where rr, gg, and bb are Hexadecimal numbers representing Red, Green and Blue respectively. For example: "#ffffff" is White, "#ff0000" is Red, "#00ff00" is Green, and "#0000ff" is Blue. To find out more about this, look at "Hexadecimal Colour Numbers".

Most newer browsers also accept common colour names, so instead of having to write "#00ff00", it's possible to simply write "green". A useful resource for colours is The 140 Color Names - this page includes 140 colour names with a colour "swatch".
Examples
<body background="http://www.fbe.unsw.edu.au/pics/bk.jpg">
This image is specified with a complete URL (use this if the image is on another site).
<body background="pic.jpg" text="#ffffff" link="#ffff00" vlink="#00ff00">
Here the foreground colours are set, in addition to a background image being specified. The text colour is white, the link colour is cyan, and the visited links colour is green.
<body background="pic.jpg" text="white" link="cyan" vlink="green">
As above, except using colour names.
<body bgcolor="#ffcc66">
The background colour is set to apricot, while the text colour remains set to black.


Go to next section: File Footer or return to the Contents page.

Last Updated: 06 November 1998