How to create a header and footer in HTML5
Use the <header> and <footer> elements of HTML5 to easily create semantic headers and bottoms to improve web structure clarity and accessibility; it can be flexibly laid out through CSS, such as using Flexbox to achieve a sticky bottom, ensuring that the footer is always at the bottom of the viewport.

Creating a header and footer in HTML5 is straightforward using the semantic <header></header> and <footer></footer> elements. These tags help define the structure of your webpage in a meaningful way, improving readability and accessibility.
Use the <header></header> and <footer></footer> Tags
HTML5 introduced semantic elements to clearly describe different parts of a webpage. The <header></header> typically contains introduction content like logos, navigation, or headings. The <footer></footer> usually includes copyright info, contact details, or links.
Here's a basic example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Header and Footer Example</title>
<style>
header, footer {
padding: 20px;
text-align: center;
background-color: #f3f3f3;
color: #333;
}
body {
margin: 0;
font-family: Arial, sans-serif;
}
main {
min-height: 70vh; /* Ensures space between header and footer */
}
</style>
</head>
<body>
<header>
<h1>My Website</h1>
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Contact</a>
</nav>
</header>
<main>
<p>Welcome to my website. This is the main content area.</p>
</main>
<footer>
<p>© 2025 My Website. All rights reserved.</p>
</footer>
</body>
</html>Key Points to Remember
- Semantic Meaning :
<header>and<footer>are not just for styling—they convey structure to browsers, screen readers, and search engines. - Multiple Headers/Footers : You can use multiple
<header>elements (eg, one for the page and one for an article), but only one primary<footer>per page is typical. - Styling Flexibility : Use CSS to position the footer at the bottom (eg, with Flexbox or Grid) if you want it to stick to the bottom of the viewport when content is short.
For a sticky footer, consider this layout tweak:
body {
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
}
main {
flex: 1;
}This ensures the footer stays at the bottom even with little content.
Basically, just wrap your top and bottom sections in <header></header> and <footer></footer> , style as needed, and use proper document flow. It's simple, semantic, and effective.
The above is the detailed content of How to create a header and footer in HTML5. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20524
7
13634
4




