The <body>
tag is one of the most important structural elements in both XHTML and HTML documents. It defines the main content area of your webpage—essentially, everything you want your visitors to see in their browser window.
In XHTML, every web page begins with the <html>
tag, which wraps the entire document. Inside this, you’ll find two major sections:
<head>
— Contains metadata, styles, scripts, and resources that aren’t displayed directly.<body>
— Contains all the visible content rendered in the browser, such as text, images, links, forms, buttons, and more.
🖥️ What Goes Inside the <body>
Tag?
Everything that users interact with or see on your website lives within the <body>
tag. This includes:
- Text content (headings, paragraphs, lists)
- Images, videos, and other media
- Navigation menus
- Buttons and form elements
- Embedded scripts (JavaScript)
- Links and icons
- HTML components like tables, divs, and sections
✍️ Example of a Basic XHTML Structure
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My XHTML Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a sample paragraph inside the body tag.</p>
<img src="image.jpg" alt="Sample Image" />
</body>
</html>
In the example above, everything between <body>
and </body>
will be displayed in the browser.
🧠 Why Not Put Visible Content in <head>
?
The <head>
section is reserved for information about the document—not its content. It typically contains:
- Page title (shown in the browser tab)
- Meta tags (used for SEO and browser behavior)
- Stylesheets (CSS)
- JavaScript files
- Icons and fonts
These resources interact with elements inside the <body>
, but they themselves are not directly shown.
🚧 Important XHTML Rules for <body>
- XHTML is more strict than HTML. You must close all tags properly.
- The
<body>
tag must be present in every well-formed XHTML document. - Use proper nesting of tags within
<body>
to maintain valid markup. - Always declare your
DOCTYPE
and XML namespace in XHTML for browser compatibility.
🧩 Summary
The <body>
tag is where all the visible, interactive content of your website lives. It forms the core of user experience, representing the structure and design that your visitors see on screen.
If you’re building webpages using XHTML, understanding how the <body>
tag functions—and how it relates to the <head>
and <html>
tags—is essential for writing clean, valid, and user-friendly code.