Live Preview
Content that would appear inside a page body:

By the end of this tutorial, you’ll understand how the body element holds every visible part of a web page.
See where <body> fits inside html and after head.
Learn what belongs in body—text, images, links, forms, and media.
Separate metadata in head from content users see in body.
Organize body content with header, main, and footer.
Style page background and typography with CSS instead of deprecated attributes.
Apply accessibility and one-body-per-page best practices.
<body> Tag?The body element (<body>) represents the main content of an HTML document—everything the user sees and interacts with in the browser window. Metadata like the page title and charset live in <head>, not in <body>.
Every HTML document has a single <body> element inside <html>. Use div, main, or section to divide content—never add a second body tag.
The body is a block-level root container for visible content: headings, paragraphs, images, links, videos, forms, and scripts that visitors see on screen.
Every HTML page follows this basic skeleton. Place all visible content between the opening and closing <body> tags:
<!-- Basic HTML document skeleton -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Your Page Title</title>
</head>
<body>
<!-- Your visible page content goes here -->
</body>
</html>body inside html, immediately after the closing </head> tag.body element per HTML document.html or head inside it.title and charset in head, not in body.| Use Case | Code Snippet | Result |
|---|---|---|
| Basic skeleton | <body>...</body> | Visible page content |
| Text content | <body><h1>...</h1><p>...</p></body> | WelcomeSample paragraph. |
| Links | <body><a href="...">...</a></body> | Visit CodeToFun |
| Semantic layout | <body><header><main><footer> | Landmark structure |
| Page styling | body { background: #f8fafc; } | CSS, not bgcolor |
| Scripts | <script>...</script> before </body> | Non-blocking load |
Every HTML page splits metadata and visible content between these two sections:
| Feature | <head> | <body> |
|---|---|---|
| Purpose | Metadata (not shown on screen) | Visible page content |
| Contains | title, charset, CSS links, SEO meta | Text, images, links, forms, media |
| Page title | Yes — <title> belongs here | No — title is not body content |
| Scripts | Allowed but uncommon | Often placed before </body> |
The <body> tag has no tag-specific attributes in HTML5. Use global attributes and CSS for styling:
class / id GlobalHook for CSS and JavaScript. Common pattern: class="page-body" or id="app".
<body class="page-body">style OptionalInline styling for quick overrides. Prefer CSS stylesheets in production for maintainability.
style="margin: 0;"Allowed content FlowAny visible HTML element: headings, paragraphs, images, links, forms, semantic landmarks, and scripts.
header, main, footer, div, p, a...Deprecated attrs AvoidDo not use bgcolor, background, or text. Style the page with CSS instead.
body { background: #f8fafc; }The body element uses global attributes only. There are no tag-specific attributes in the HTML5 specification.
Real-world body content patterns with copy-ready code, live previews, and hands-on practice.
Content that would appear inside a page body:
Headings and paragraphs are the most common content inside <body>.
<body>
<h1>Welcome to My Website</h1>
<p>This is a sample paragraph inside the body.</p>
</body>The body can contain any visible HTML element: text, images, links, lists, tables, forms, videos, and semantic layout sections.
Place images inside <body> so they appear on the page. Always include meaningful alt text.
<body>
<img src="/images/javascript.png" alt="JavaScript logo" width="128" height="128">
</body>Hyperlinks go inside <body> so users can click and navigate.
<body>
<p>Visit our tutorials:</p>
<a href="https://codetofun.com">Visit CodeToFun</a>
</body>A complete beginner-friendly page with header, main, and footer inside <body>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Web Page</title>
</head>
<body>
<header><h1>My Website</h1></header>
<main><p>All visible content goes here.</p></main>
<footer><p>© 2026 CodeToFun</p></footer>
</body>
</html>Set page-wide defaults for background, typography, and spacing:
default Browser marginsmargin: 0 Reset body marginbackground Page backgroundfont-family Base typography/* Page-wide defaults */
body {
margin: 0;
font-family: system-ui, sans-serif;
background: #f8fafc;
color: #334155;
line-height: 1.6;
}
/* Avoid deprecated bgcolor attribute */
/* Use CSS background instead */Typical body content styling
Styled with CSS applied to the body element.
Structure inside <body> affects accessibility:
header, main, nav, and footer help screen reader users navigate.main element.html, not body, for correct pronunciation.DOCTYPE and html tell the browser this is an HTML page.
Title, charset, and linked CSS load from head without appearing on screen.
Everything inside body is painted in the browser window for the user.
head + body = metadata plus everything visitors see and interact with.
The <body> element is supported in all browsers and has been part of HTML since the earliest versions.
From legacy Internet Explorer to the latest Chromium builds — the body element is the universal container for every web page ever built.
Bottom line: Ship page content with confidence. The <body> element is safe to use in every production environment today.
The <body> tag is the foundation of every web page—all visible content lives inside it. Pair it with a proper <head> section and semantic elements like main and header for clean, accessible HTML.
body per HTML pagemain</body>title or charset meta inside bodybody tags on one pagebgcolor or background (deprecated)html or head inside body<body>Bookmark these before you ship — they’re the foundation of every web page.
<body> holds all content users see—text, images, links, and forms.
Exactly one body element per HTML document—no exceptions.
RuleGoes inside html, immediately following the closing </head> tag.
head = metadata; body = visible page content.
Use header, main, and footer inside body for accessibility.
Use CSS for background and typography—not deprecated bgcolor.
html, after the closing </head> tag. Every page has exactly one body.head holds metadata (title, charset, CSS links). body holds the visible page content.body per page. Divide content with div, main, section, or other elements inside it.body { background: #f8fafc; }. Do not use the deprecated bgcolor attribute.Practice the html, head, and body structure in the Try It editor.
6 people found this page helpful