HTML <body> Tag โ Visible Page Content
๐ Introduction
The <body> tag contains all the content that is visible to users in the browser.
Everything you see on a webpage is inside the <body>, such as:
- Text
- Images
- Links
- Buttons
- Forms
๐งฑ Basic Syntax
<body>
<!-- Visible content goes here -->
</body>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome</h1>
<p>This is my website.</p>
<button>Click me</button>
</body>
</html>
๐ฅ๏ธ Output Explanation
The browser will display:
- A heading: Welcome
- A paragraph: This is my website.
- A button: "Click me"
Everything shown comes from the <body> section.
๐ฏ What Goes Inside <body>
Common elements:
- Headings (
<h1>โ<h6>) - Paragraphs (
<p>) - Images (
<img>) - Links (
<a>) - Lists (
<ul>,<ol>) - Forms (
<form>)
โ ๏ธ Important Rules
- Only one
<body>tag per page - Must be inside
<html> - Comes after
<head>
โ Correct structure:
<html>
<head></head>
<body></body>
</html>
โก Attributes of <body>
Example:
<body style="background-color: lightgray;"></body>
โ You can apply styles directly (not recommended for large projects)
โ ๏ธ Tips & Best Practices
- Keep your content well organized
- Use semantic tags (
<header>,<section>,<footer>) inside<body> - Avoid inline styles โ use CSS instead
- Place
<script>at the end of<body>for better performance
๐ซ Common Mistakes
- Adding content outside
<body>โ - Using multiple
<body>tags โ - Mixing structure and styling too much โ
๐งช Mini Exercise
Create a page with:
- A heading
- A paragraph
- A button
Then:
- Add another section with your name and goals