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

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

Mobile browser support

Chrome
18+
Firefox
4+
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>