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
<body>
<!-- Visible page content goes here -->
</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
<!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
| Attribute | Description |
|---|---|
| onload | Fires when the document has finished loading. |
| onunload | Fires when the document is being unloaded. |
| onresize | Fires 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.
