asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Language References > HTML Elements > BODY Element

<body> Element


Represents the main content of the document.HTML 2, 3.2, 4, 4.01, 5

HTML Syntax

NOTE: Both start and end tags are ommissible, in certain situations.

Remarks

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.

Attributes

The <body> element supports the following attributes, in addition to global attributes common to all HTML elements.

AttributeValueDescription
alinkcolorSpecifies the color of active link (while the mouse button is held down during a click) in a document.
backgroundURLSpecifies a background image for the document.
bgcolorcolorSpecifies the background color of the document.
linkcolorSpecifies the color of unvisited links in a document.
textcolorSpecifies the foreground color for text in a document.
vlinkcolorSpecifies the color of visited links (links that have already been followed) in a document.

Example

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 

External References

See Also

HTML   HEAD   IFRAME



Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note