Codectionary / Developer documentation / HTML

<body>

The <body> element contains all the visible content of an HTML document — text, images, links, forms, and everything a user actually sees and interacts with in the browser. There can only be one <body> per document, and it must come after the <head> element. Unlike <head>, which holds metadata, everything inside <body> is rendered on the page.

Syntax

<body>
  <h1>Visible content goes here</h1>
</body>

Examples

Basic Body Content

A body containing typical page content.

<body>
  <h1>Welcome</h1>
  <p>This is the visible content of the page.</p>
</body>

Body with Event Attributes

Attaching a page-load event directly to body (though addEventListener is generally preferred).

<body onload="console.log('Page loaded')">
  <p>Content...</p>
</body>

Full Document Structure

Seeing body in context alongside head.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My Page</title>
</head>
<body>
  <h1>My Page</h1>
  <p>Content visible to the user.</p>
</body>
</html>

Best practices

  • Only one <body> element is allowed per document
  • Keep metadata like <title>, <meta>, and <link> in <head>, not <body>
  • Prefer addEventListener in a script over inline event attributes like onload for cleaner separation of concerns
  • Everything a user can see or interact with belongs inside <body>

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation