Header, Footer & Main
Master the essential structural elements of HTML pages. Learn to create proper page layouts with semantic header, main, and footer elements for better accessibility and SEO.
What are the header, main and footer elements?
<header> contains introductory content like a logo, site title or navigation. <main> wraps the page's unique primary content, and there should be only one visible per page. <footer> holds closing information such as copyright, contact details and secondary links. They define landmark regions that assistive technology can jump to.
<header>
<a href="/">Compileum</a>
<nav>…</nav>
</header>
<main id="content">…</main>
<footer>
<p>© 2025 Compileum</p>
</footer>Try It: Essential Page Structure
Explore a complete page structure using header, main, and footer elements. See how they work together to create accessible, semantic layouts.
Code Editor
<header>
<strong>Compileum</strong>
<nav><a href="#">Tutorials</a> <a href="#">Playground</a></nav>
</header>
<main>
<h1>Page title</h1>
<p>The main, unique content of the page goes here.</p>
</main>
<footer>© 2026 Compileum · <a href="#">Privacy</a></footer>Preview
The Header Element
The header element represents introductory content, typically containing navigation, branding, and page titles. It can appear multiple times on a page.
Header Characteristics:
- Contains introductory content
- Usually includes site navigation
- Can contain branding elements
- Multiple headers allowed per page
- Often sticky or fixed positioned
Common Header Content:
- • Site logo and branding
- • Primary navigation menu
- • Search functionality
- • User account controls
- • Contact information
- • Call-to-action buttons
Header Usage Examples:
Site Header:
<!-- Global site header -->
<header class="site-header">
<div class="container">
<h1 class="logo">My Website</h1>
<nav class="main-nav">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</div>
</header>Article Header:
<!-- Article-specific header -->
<article>
<header class="article-header">
<h2>Article Title</h2>
<p class="meta">
By <a href="/author">John Doe</a>
on <time>March 15, 2025</time>
</p>
</header>
<p>Article content...</p>
</article>The Main Element
The main element represents the dominant content of the page. There should be only one main element per page, and it should not contain repeated content.
Important Main Element Rules:
Must Have:
- • Only one per page
- • Contains unique, primary content
- • Excludes repeated navigation
- • Excludes headers and footers
- • Should be directly accessible
Should Not:
- • Be nested inside article, aside, nav
- • Contain site-wide repeated content
- • Include navigation menus
- • Include copyright information
- • Be used multiple times
Main Element Best Practices:
<!-- Good: Single main with primary content -->
<main>
<section class="hero">
<h1>Welcome to Our Site</h1>
<p>This is the main content area.</p>
</section>
<section class="content">
<article>
<h2>Main Article</h2>
<p>Primary content here...</p>
</article>
</section>
</main>
<!-- Good: Main with skip link for accessibility -->
<a href="#main" class="skip-link">Skip to main content</a>
<header>...</header>
<main id="main">
<!-- Primary content -->
</main>
<!-- Bad: Multiple main elements -->
<main>Content 1</main>
<main>Content 2</main> <!-- WRONG: Only one allowed -->
<!-- Bad: Main inside other elements -->
<article>
<main>Content</main> <!-- WRONG: Cannot be nested -->
</article>The Footer Element
The footer element represents the footer for its nearest sectioning content. It typically contains metadata, copyright, and supplementary information.
Footer Characteristics:
- Contains concluding information
- Usually at bottom of sections
- Can contain navigation links
- Multiple footers allowed per page
- Often contains metadata
Common Footer Content:
- • Copyright and legal information
- • Contact details
- • Secondary navigation
- • Social media links
- • Newsletter signup
- • Related links and resources
Footer Usage Examples:
Site Footer:
<!-- Global site footer -->
<footer class="site-footer">
<div class="footer-content">
<div class="footer-section">
<h3>Company</h3>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/careers">Careers</a></li>
</ul>
</div>
<div class="footer-section">
<h3>Contact</h3>
<p>Email: info@company.com</p>
</div>
</div>
<div class="footer-bottom">
<p>© 2025 Company. All rights reserved.</p>
</div>
</footer>Article Footer:
<!-- Article-specific footer -->
<article>
<header>
<h2>Article Title</h2>
</header>
<p>Article content...</p>
<footer class="article-footer">
<p>Tags:
<a href="/tag/html">HTML</a>,
<a href="/tag/tutorial">Tutorial</a>
</p>
<p>Published: March 15, 2025</p>
<p>Author: John Doe</p>
</footer>
</article>Complete Page Structure
Here's how to properly structure a complete HTML page using header, main, and footer elements together for optimal accessibility and SEO.
Complete Page Template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
</head>
<body>
<!-- Skip link for accessibility -->
<a href="#main" class="skip-link">Skip to main content</a>
<!-- Site header with navigation -->
<header class="site-header">
<div class="container">
<h1 class="logo">
<a href="/">Site Name</a>
</h1>
<nav class="main-navigation" aria-label="Main">
<ul>
<li><a href="/" aria-current="page">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/services">Services</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</div>
</header>
<!-- Main content area -->
<main id="main">
<!-- Hero section -->
<section class="hero">
<h2>Page Title</h2>
<p>Page description or introduction</p>
</section>
<!-- Primary content -->
<section class="content">
<article>
<header>
<h3>Article Title</h3>
<p class="meta">Published on <time datetime="2025-03-15">March 15, 2025</time></p>
</header>
<div class="article-body">
<p>Article content goes here...</p>
</div>
<footer class="article-footer">
<p>Tags: <a href="/tag/html">HTML</a>, <a href="/tag/tutorial">Tutorial</a></p>
</footer>
</article>
</section>
<!-- Sidebar (optional) -->
<aside class="sidebar">
<section class="widget">
<h4>Related Articles</h4>
<ul>
<li><a href="/related-1">Related Article 1</a></li>
<li><a href="/related-2">Related Article 2</a></li>
</ul>
</section>
</aside>
</main>
<!-- Site footer -->
<footer class="site-footer">
<div class="footer-content">
<section class="footer-section">
<h5>About Us</h5>
<p>Brief description of the organization.</p>
</section>
<section class="footer-section">
<h5>Quick Links</h5>
<nav aria-label="Footer">
<ul>
<li><a href="/privacy">Privacy Policy</a></li>
<li><a href="/terms">Terms of Service</a></li>
<li><a href="/sitemap">Sitemap</a></li>
</ul>
</nav>
</section>
<section class="footer-section">
<h5>Contact</h5>
<address>
<p>Email: <a href="mailto:info@example.com">info@example.com</a></p>
<p>Phone: <a href="tel:+15551234567">(555) 123-4567</a></p>
</address>
</section>
</div>
<div class="footer-bottom">
<p>© 2025 Your Company Name. All rights reserved.</p>
</div>
</footer>
</body>
</html>Accessibility Benefits
- • Clear page landmarks
- • Skip navigation links
- • Proper heading hierarchy
- • Screen reader navigation
SEO Advantages
- • Better content understanding
- • Improved crawling
- • Enhanced search features
- • Structured data compatibility
Maintenance Benefits
- • Clear code organization
- • Easier styling with CSS
- • Better team collaboration
- • Future-proof structure
Best Practices & Guidelines
Best Practices:
- Use semantic landmarks
Header, main, footer provide clear page structure
- Include skip links
Help keyboard users navigate efficiently
- Use ARIA labels
Add aria-label to navigation elements
- Keep content organized
Group related content logically
Common Mistakes:
- ✗Multiple main elements
Only one main element per page
- ✗Nesting main incorrectly
Main cannot be inside article, aside, nav
- ✗Using for styling only
Use semantic meaning, not just CSS hooks
- ✗Missing accessibility features
Include skip links and proper labels
Header, Footer, and Main — step by step
Add a page header
The header element contains introductory content, typically the site logo, page title, and primary navigation. It can also appear inside an article or section as a section header.
🎯 Quick Check
What ARIA landmark role does the main element have when it is a direct child of the body?
HTML header, main and footer: summary
Key points
<header>and<footer>can also be used inside an<article>or<section>for that piece's own header and footer.- Only the page-level header and footer become the "banner" and "contentinfo" landmarks.
- A skip link like
<a href="#content">Skip to content</a>pairs naturally with<main id="content">.
Frequently asked questions
›Can a page have more than one header?
Yes. Each <article> or <section> can have its own <header>. Only one <main> should be visible at a time, though.
›Is the <header> element the same as the <head>?
No. <head> holds page metadata and isn't visible. <header> is visible content at the top of the page or of a section.