HTML Tutorial

HTML Tag: <body>

Usage of <body>

The <body> tag defines the main content of an HTML document. It contains all the visible elements on a web page, including text, images, videos, and interactive elements.

Attributes of <body>

The <body> tag has several attributes that can be used to customize its appearance and functionality:

  • background: Sets the background color or image of the body.
  • bgcolor: Alias for background-color, which sets the background color.
  • text: Sets the default text color.
  • link: Sets the default color of links.
  • vlink: Sets the default color of visited links.
  • alink: Sets the default color of active links.

Examples with <body>

<body>
  <h1>Hello World</h1>
  <p>This is my first HTML page.</p>
</body>

In this example, the <body> tag contains a heading and a paragraph. The background color is set to white using the background-color attribute.

<body background="image.jpg">
  <h1>Welcome to our website</h1>
  <p>Explore our latest products and services.</p>
</body>

In this example, the background image of the body is set to image.jpg.

Exploring the <body> Tag

To explore the <body> tag, open your favorite text editor and create a new HTML file. Type the following code:

<!DOCTYPE html>
<html>
<body>
  <h1>Hello World</h1>
  <p>This is my first HTML page.</p>
</body>
</html>

Save the file and open it in a web browser. You should see a web page with a heading that says "Hello World" and a paragraph that says "This is my first HTML page."

Accessibility and Ease of Use

When using the <body> tag, consider the following accessibility and ease of use best practices:

  • Use semantic HTML elements: Use tags like <h1> for headings and <p> for paragraphs instead of relying solely on the <body> tag to define the content.
  • Provide high-contrast text: Ensure there is sufficient contrast between the text and background colors to make it easy to read.
  • Avoid using blinking or scrolling text: These elements can be distracting and difficult for some users to focus on.