HTML <body> (Document Body) Tag

❮ Previous Reference Next ❯

Example

<!DOCTYPE html>
<html>
<body>

<h1>This is a Heading</h1>

<p>This is a paragraph.</p>

</body>
</html>

Meaning

The <body> element represents the main content of the document.

Note: There can only be one <body> element in an HTML document.

Version: HTML 2, 3.2, 4, 4.01, 5


Standard Syntax

<body>...</body>



Browser Support




Status







Deprecated Attributes

Attribute Value Description
alink named color|hexadecimal This attribute sets the color for active links within the document.
background URL This attribute contains a URL for an image file, which will be tiled to provide the document background.
bgcolor named color|hexadecimal This attribute sets the background color for the document. use CSS background property on the element instead.
bottommargin number This attribute specifies the bottom margin for the entire body of the page and overrides the default margin. Use CSS margin properties instead.
leftmargin number This Internet Explorer–specific attribute sets the left margin for the page, in pixels, overriding the default margin. CSS margin properties should be used instead.
link named color|hexadecimal This attribute sets the color for hyperlinks within the document that have not yet been visited. The CSS pseudo-class a:link should be used instead.
marginheight number This attribute sets the top margin for the document, in pixels. CSS margin properties should be used instead.
marginwidth number This attribute sets the left and right margins for the page, in pixels, overriding the default margin. CSS margin properties should be used instead.
nowrap yes|no This attribute is used to control the wrapping of text body width. The default is no.
bgproperties - This attribute make the background image to act as a fixed watermark and not to scroll. The CSS property background-attachment provides similar functionality.
rightmargin number This attribute sets the right margin for the page in pixels, overriding the default margin. CSS margin properties should be used instead.
scroll yes|no This attribute turns the scroll bars on or off. The default value is yes.
text named color|hexadecimal This attribute sets the text color for the document.
topmargin number This attribute sets the top margin for the document, in pixels. CSS margin properties should be used instead.
vlink named color|hexadecimal This attribute sets the color for hyperlinks within the document that have already been visited. The CSS pseudo-class a:visited should be used



Global Attributes

<body> element also supports the Global Attributes in HTML.


Event Attributes

<body> element also supports the Event Attributes in HTML.


More Examples

Set background image to a document

Example

<style>
  body {
    background-image: url(smiley.png);
  }
</style>

Set background color and text color to a document

Example

<style>
body {
  background-color: red;
  color: white;
}
</style>

Set color to anchor tag

Example

<style>
  a:link {
    color: red;
  }
  a:active {
    color: green;
  }
  a:visited {
    color: yellow;
  }
</style>

By Default CSS Value(s)

Most of the browsers will display the <body> element with the following by default value(s)

body {
	display: block;
	margin: 8px;
}

body:focus {
	outline: none;
}
❮ Previous Reference Next ❯