HTML <main> Tag β Main Content Area
π Introduction
The <main> tag is used to define the main content of a webpage.
It contains the content that is directly related to the pageβs primary purpose.
π There should only be one <main> per page.
π§± Syntax
<main>Content here</main>
π‘ Example
<!DOCTYPE html>
<html>
<head>
<title>Main Example</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<main>
<h2>Welcome</h2>
<p>This is the main content of the page.</p>
</main>
<footer>
<p>Β© 2026 My Website</p>
</footer>
</body>
</html>
π₯οΈ Output Explanation
- The
<main>section contains the primary content - It is separate from header and footer
- Helps browsers and screen readers understand structure
π― What Goes Inside <main>?
Common elements:
- Articles
- Blog posts
- Page content
- Forms
- Key information
Example:
<main>
<h2>Courses</h2>
<p>Learn HTML step by step.</p>
</main>
π§ Important Rule
π Only one <main> per page
β Wrong:
<main></main>
<main></main>
β Correct:
<main></main>
βοΈ <main> vs <div>
| Tag | Purpose |
|---|---|
<main> |
Main page content (semantic) |
<div> |
Generic container |
β Use <main> for real page content
β Donβt use it for layout blocks
π― Why <main> is Important
- Improves SEO structure
- Helps accessibility tools
- Clearly defines page purpose
- Used in modern HTML layouts
π« Common Mistakes
- Using multiple
<main>tags β - Putting navigation or footer inside
<main>β - Using it just like a
<div>β
π¨ Styling Example
<main style="padding:20px;">
<h2>Welcome</h2>
<p>Main content area</p>
</main>
π§ͺ Mini Exercise
Create a page with:
<header><main>containing:- A title
- A paragraph
<footer>Style the main section with padding and background color