Home > Abakada: Back to Basics > Language References > HTML Elements > BODY Element
Represents the main content of the document. | HTML 2, 3.2, 4, 4.01, 5 |
HTML Syntax
<body alink=color background=url bgcolor=color
link=color text=color vlink=color>
...
</body>
NOTE: Both start and end tags are ommissible, in certain situations.
The <body
> element represents the contents of the document.
The document’s content may be presented by a user agent in a variety of ways.
For visual browsers, you can think of the body as a canvas where text, images, lists, tables, and other elements may appear.
For audio user agents, the same content may be spoken.
NOTE: There can only be one <body
> element in a document.
HTML 3.2 introduced attributes wherein an author can specify characteristics for the <body
>, such as the background color or an image to use as a tiled background, the default text color, and the colors for active, unvisited and visited links.
Since style sheets are now the preferred way to specify a document’s presentation, the presentational attributes of <body
> have been deprecated in favor of CSS styles.
Still they are included in this workshop for backward compatibility with downlevel browsers.
The body element can be used with script to respond to events.
Actions can be specified to occur when the document finishes loading ( onload ) or is unloaded ( onunload ), and when the window in which the document is displayed receives ( onfocus ) or loses focus ( onblur ).
In script, the body element is accessed using the body property on the document object.
A body element’s start tag can be omitted if the element is empty, or if the first thing inside the body element is not ASCII whitespace or a comment, except if the first thing inside the body element is a meta, noscript, link, script, style, or template element.
A body element’s end tag can be omitted if the body element is not immediately followed by a comment.
The <body>
element supports the following attributes, in addition to global attributes common to all HTML elements.
alink | color | Specifies the color of active link (while the mouse button is held down during a click) in a document. |
background | URL | Specifies a background image for the document. |
bgcolor | color | Specifies the background color of the document. |
link | color | Specifies the color of unvisited links in a document. |
text | color | Specifies the foreground color for text in a document. |
vlink | color | Specifies the color of visited links (links that have already been followed) in a document. |
The following shows how the body element may be used.
<html>
<head>
<title>Sample HTML document</title>
</head>
<body>
<h1>Hello, World.</h1>
</body>
</html>
Show me
The following example sets the background color of the document to beige, text to black, unvisited links to blue, visited links to green, and active links to red.
<body bgcolor="beige" text="black" link="blue" vlink="green" alink="red">
...
</body>
Show me
HTML HEAD IFRAME