It’s Festive Season! Enjoy 30% Off

Use code FESTIVE30 at checkout

Code has been added to clipboard!

HTML body Tag

Reading time 2 min
Published Jun 29, 2017
Updated Oct 2, 2019

HTML body Tag: Main Tips

  • HTML <body> element holds the content of web pages.
  • In HTML documents, the <body> element must go immediately after <html>.

Use and Purpose of body

HTML <body> tag defines the container HTML, holding the contents of an document.

Example
<body>
  <h1>Hello World</h1>
  <p>This is the main part of your document.</p>
</body>

Such an HTML document is defined by <html> element, which has two child elements: the <head> and the <body>.

Tip: the <body> HTML element is a suitable location to place all the CSS, modifying the HTML document - background and text colors, fonts, etc.

Available Attributes

onFocus

It specifies a function to invoke after the document receives focus.

Example
<body onFocus="function">

onLoad

It sets a function to call after the HTML document loads.

Example
<body onLoad="function">

onUnload

It indicates a function for when users close the HTML document.

Example
<body onUnload="function">

Deprecated Attributes in HTML5

alink

It sets active link text color.

Instead use :active selector and CSS property color. Learn how in the CSS Selector and CSS color tutorials.

Example
<body alink="yellow">
  <h1>HTML Body Tag Example</h1>
  <p>The link to <a href="https://www.bitdegree.org/">the best way to learn programming</a>.</p>
</body>

background

It sets a background image for a document.

Instead use CSS property background-image. Learn how in the CSS Backgrounds tutorial.

Example

<body background="doggo.png">
  <h1>HTML Body Tag Example</h1>
  <p>The background attribute sets a background image for this document.</p>
</body>

bgcolor

It specifies a background color for a document.

Instead use CSS property background-color. Learn how in the CSS Backgrounds tutorial.

Example

<body bgcolor="lime">
  <h1>HTML Body Tag Example</h1>
  <p>The bgcolor attribute sets a background color for this document.</p>
</body>

link

It indicates the text color of an unvisited link.

Instead use :link selector and CSS property color. Learn how in the CSS Selector and CSS color tutorials.

Example

<body link="indigo">
  <h1>HTML Body Tag Example</h1>
  <p>The link to <a href="https://www.bitdegree.org/">the best way to learn programming</a>.</p>
</body>

text

It specifies text color in a document.

Instead use CSS property color. Learn how in the CSS color tutorial.

Example

<body text="indigo">
  <h1>HTML Body Tag Example</h1>
  <p>The text color of this document is "Indigo".</p>
</body>

vlink

It sets visited link text color.

Instead use :visited selector and CSS property color. Learn how in the CSS Selector and CSS color tutorials.

Example

<body vlink="orange">
  <h1>HTML Body Tag Example</h1>
  <p>The link to <a href="https://www.bitdegree.org/">the best way to learn programming</a></p>
</body>

Browser support

Browser image
Chrome
1+
Browser image
Edge
12+
Browser image
Firefox
1+
Browser image
IE
All
Browser image
Opera
All
Browser image
Safari
All

Mobile browser support

Browser image
Chrome
18+
Browser image
Firefox
4+
Browser image
Opera
All
Browser image
Safari
All