MyInternships.in

HTML Tags

HTML <body> Tag

The <body> tag contains all the content of an HTML document that is displayed to users, such as text, images, links, and lists. There is exactly one <body> per page.


The <body> Tag

The <body> element represents the content of an HTML document. Everything a visitor actually sees, headings, paragraphs, images, links, tables, forms, lives inside it. It comes after the <head> and is the second child of <html>.

A document has exactly one <body>. It also supports several event attributes, such as onload, that fire in response to page or window events.

Syntax

The body wraps all visible content.
Example
<body>
  <!-- Visible page content goes here -->
</body>

Example

Heading, paragraph, image, and link inside the body.
Example
<!DOCTYPE html>
<html>
  <head>
    <title>Body Demo</title>
  </head>
  <body>
    <h1>My Web Page</h1>
    <p>This paragraph is inside the body, so it is visible.</p>
    <img src="https://picsum.photos/200" alt="A sample image" />
    <p><a href="https://www.wikipedia.org/">A link to Wikipedia</a></p>
  </body>
</html>

More Examples

Using the onload event attribute on <body>.
Example
<!DOCTYPE html>
<html>
  <body onload="document.body.style.background='#e7f5ff'">
    <h1>Page with an onload event</h1>
    <p>The background colour is set when the page finishes loading.</p>
  </body>
</html>

Attributes

AttributeDescription
onloadFires when the document has finished loading.
onunloadFires when the document is being unloaded.
onresizeFires when the browser window is resized.
⚠️

Presentational attributes like bgcolor, text, and background are deprecated. Use CSS to style the body instead.

Key Takeaways

  • <body> holds all visible page content.
  • There is exactly one <body> per document.
  • It follows <head> as the second child of <html>.
  • It supports window and document event attributes like onload.
  • Style it with CSS, not deprecated presentational attributes.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships