w3resource

HTML body tag and element

1. HTML body element represents the main content of an HTML page.

2. In an HTML document, only one body element can exist.

Syntax

<body>other elements </body> 

Category

HTML html element is part of the global structure of an HTML page.

Whether both start and end tags are required

Both start and end tags are optional.

Can contain

HTML html element can contain inline as well as block level elements.

Can reside within

HTML html element.

DOCTYPE support

HTML 4.01 Strict, HTML 4.01 Transitional.

Attributes

Attributes specific to this element

Attribute Value Description
background An URL. Specifies an background image. This attribute is deprecated against styles.
text rgb value, hexadecimal value or name for a color. Specifies text color for body of an HTML page. This attribute is deprecated against styles.
link rgb value, hexadecimal value or name for a color. Specifies text color for hyperlinks present in body of an HTML page. This attribute is deprecated against styles.
alink rgb value, hexadecimal value or name for a color. Specifies text color for active hyperlinks in body of an HTML page. This attribute is deprecated against styles.
vlink rgb value, hexadecimal value or name for a color. Specifies text color for visited hyperlinks in body of an HTML page. This attribute is deprecated against styles.

Identifiers

id and class.

language information and text direction

lang, dir.

Title

title.

Style

style.

Events

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup.

bgcolor

bgcolor attribute is used to set background color of body of an HTML page. Value of the bgcolor may be a rgb value, a hexadecimal value or a name for a color.

Example of using HTML body element

Bellow is a simple HTML page where body element contains some text within a paragraph.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>html body tag example</title>
</head>
<body>
<p>We are learning HTML body element. </p>
</body>
</html>

Result

html body tag and element

View this example in a separate browser window

HTML body tag example.

Online practice editor

HTML body tag example.

Pictorial presentation

html-body-tag

Previous: HTML meta tag and element
Next: HTML div tag and element