<body>

The HTML <body> element encompasses the primary content of an HTML document, including text, images, and media, which is displayed in the browser for users.

<body> Tag

The HTML <body> element defines the primary content of a webpage. Each HTML document can contain only one <body> tag.

Syntax

index.html
<body>
  <!-- Content goes here -->
</body>

<body> Demo

Welcome to My Website

This is a paragraph of text.

A descriptive image https://institute.qarpeo.com
index.html
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text.</p>
<img src="img.jpg" alt="A descriptive image">
<a href="https://institute.qarpeo.com">Visit https://institute.qarpeo.com</a>
The <body> tag contains all visible content, including a heading <h1>, a paragraph <p>, an image <img>, and a link <a>.

Examples

  • Set text color using CSS:

This is some text.

https://institute.qarpeo.com

index.html
<!DOCTYPE html>
<html>
<head>
<style>
body {
  color: green;
}
</style>
</head>
<body>

<p>This is some text.</p>
<p><a href="https://institute.qarpeo.com">Visit https://institute.qarpeo.com</a></p>

</body>
</html>
  • Set color for unvisited links using CSS:

https://institute.qarpeo.com

HTML Tutorial

index.html
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
  color: #FF0000;
}
</style>
</head>
<body>

<p><a href="https://institute.qarpeo.com">https://institute.qarpeo.com</a></p>
<p><a href="https://institute.qarpeo.com/cs/html">HTML Tutorial</a></p>

</body>
</html>

Purpose and Usage

  • The <body> element defines the main content area of an HTML document.
  • It includes visible elements like headings, paragraphs, images, links, tables, and lists.
An HTML document must contain only one <body> element.

See Also

Conclusion

The <body> tag in HTML is essential for defining the main content of a webpage, containing all visible elements like text, images, and links. It is the part of the document that is displayed to users in the browser. Each HTML document should have only one <body> tag, and it can include global attributes and event handlers like onload, onerror, onresize and onunload to enhance interactivity.