HTML Tutorial: Complete HTML Tutorial
About Lesson

HTML <body> Tag


The <body> tag in HTML is used to define the main content of the HTML document or the section of the HTML document that will be directly visible on your web page. It contains all the contents of an HTML document, such as text, hyperlinks, images, tables, lists, etc.

Implementation

Example 1: Basic Structure

<!DOCTYPE html>
<html>
<head>
  <title>My Page</title>
</head>
<body>
  <h1>Welcome to My Page</h1>
  <p>This is a paragraph inside the body tag.</p>
</body>
</html>
Sponsored by Google

Try it below

powered by Advanced iFrame. Get the Pro version on CodeCanyon.

Example 2: Including Multimedia

<!DOCTYPE html>
<html>
<head>
  <title>My Multimedia Page</title>
</head>
<body>
  <h1>Welcome to My Multimedia Page</h1>
  <img src="image.jpg" alt="An example image">
  <video src="video.mp4" controls></video>
  <audio src="audio.mp3" controls></audio>
</body>
</html>

Example 3: Using Forms and Tables

<!DOCTYPE html>
<html>
<head>
  <title>My Form Page</title>
</head>
<body>
  <h1>Sign Up Form</h1>
  <form action="submit.php" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>
    <input type="submit" value="Submit">
  </form>
  <table>
    <tr>
      <th>Name</th>
      <th>Email</th>
    </tr>
    <tr>
      <td>John Doe</td>
      <td>john@example.com</td>
    </tr>
  </table>
</body>
</html>

Browser Support

Browser Support
Chrome Yes
Firefox Yes
Safari Yes
Edge Yes
Internet Explorer Yes

Global Attributes

The <body> tag also supports the Global Attributes in HTML.

Event Attributes

The <body> tag also supports the Event Attributes in HTML.

Default CSS Settings

body {
  display: block;
  margin: 8px;
}
body:focus {
  outline: none;
}

Conclusion

The <body> tag is indeed one of the most vital elements in HTML, serving as the container for all the content that defines a web page. Its versatility allows for the inclusion of various elements, from simple text to complex multimedia components, forms, and tables.


Understanding the <body> tag is fundamental to web development, as it’s the starting point for crafting engaging and interactive web experiences.