HTML: the body element

The <body> element contains the page content that users can see or interact with, such as headings, text, images, and controls.

What you will learn

Basic document structure

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My page</title>
</head>
<body>
  <h1>Welcome</h1>
  <p>This text is part of the visible page.</p>
</body>
</html>

The head stores metadata and resource links. The body stores the document's visible and interactive content. Keep one body element in the document.

Organize the content

<body>
  <header>Site navigation</header>
  <main>
    <h1>Learning HTML</h1>
    <p>The main lesson goes here.</p>
  </main>
  <footer>Contact information</footer>
</body>

Use meaningful structural elements inside the body. This helps people scan the page and helps assistive technology understand landmarks.

CSS and JavaScript

Use CSS to control presentation and JavaScript to add behavior. JavaScript can access the element with document.body, but it should not replace meaningful HTML structure.

Common mistakes