How to use HTML header and footer elements
Use <header> and <footer> can provide semantic structure for web pages, improving accessibility, SEO and code maintainability; 2. <header> is used to define introductory content of pages or chapters, such as titles, navigation, author information, etc., which can be used in the page and article many times; 3. <footer> is used to define ending content, such as copyright information, contact information, and author information, and can also exist independently in the page and each <article>; 4. Both should be used based on semantics rather than visual layout, avoiding only for style control or incorrect nesting; 5. Correctly combining CSS and other semantic tags (such as
Using HTML <header></header>
and <footer></footer>
elements helps structure your web pages semantically, making them more accessible and easier to maintain. These are not just visual containers — they carry meaning in the document outline and are useful for SEO and screen readers.

What <header></header>
and <footer></footer>
Actually Mean
The <header></header>
and <footer></footer>
elements define introduction and closing content for a section or the entire page. They are semantic HTML5 elements , so they describe the purpose of the content inside them.
-
<header></header>
typically contains:- Page or section title (
<h1></h1>
–<h6></h6>
) - Logo
- Navigation links
- Author name, publish date (in an article)
- Page or section title (
-
<footer></footer>
usually includes:- Copyright info
- Contact details
- Sitemap or related links
- Author info (in an article)
They don't have to appear at the top or bottom visually — though they usually do — but they should represent the header or footer of a section logically.

How to Use <header></header>
You can use <header></header>
at the page level or within sections.
1. Page-level header
<header> <h1>My Website</h1> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> </nav> </header>
2. Within an article or section
<article> <header> <h2>Article Title</h2> <p>Published on <time datetime="2024-04-01">April 1, 2024</time></p> </header> <p>This is the article content...</p> </article>
Note: You can have multiple
<header>
elements on a single page — one for the page, and one for each<article>
or<section>
.
How to Use <footer>
Like <header>
, <footer>
can appear at the page level or within content sections.
1. Page-level footer
<footer> <p>© 2024 My Website. All rights reserved.</p> <p><a href="/contact">Contact us</a></p> </footer>
2. Inside an article
<article> <h2>Blog Post</h2> <p>Some content here...</p> <footer> <p>Written by: Jane Doe</p> </footer> </article>
Important: A
<footer>
inside an<article>
applies only to that article, not the whole page.
Common Mistakes to Avoid
- Don't use
<header>
or<footer>
just for styling. If you need a container for layout, use<div>
or<section>
instead. - Avoid putting
<header>
at the end or<footer>
at the beginning unless it makes semantic sense. - Don't wrap entire pages in a single
<header>
or<footer>
— use them appropriately within the document structure.
Styling with CSS
These elements are block-level, so you can style them like any container:
header { background-color: #f3f3f3; padding: 20px; text-align: center; } footer { background-color: #333; color: white; padding: 10px; text-align: center; margin-top: 20px; }
You might want to style nested headers or footers differently:
article header { text-align: left; padding: 10px 0; }
Accessibility and SEO Benefits
Using <header></header>
and <footer></footer>
helps:
- Screen readers understand page structure
- Search engines better index your content
- Developers read and maintain code more easily
They work well with other semantic tags like <main></main>
, <nav></nav>
, and <article>
to build a clean, meaningful layout.
Basically, use <header></header>
for introduction content and <footer></footer>
for closing content — whether for the whole page or just a section. It's not just about looks; it's about meaning.
The above is the detailed content of How to use HTML header and footer elements. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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)

It is a block-level element, used to divide large block content areas; it is an inline element, suitable for wrapping small segments of text or content fragments. The specific differences are as follows: 1. Exclusively occupy a row, width and height, inner and outer margins can be set, which are often used in layout structures such as headers, sidebars, etc.; 2. Do not wrap lines, only occupy the content width, and are used for local style control such as discoloration, bolding, etc.; 3. In terms of usage scenarios, it is suitable for the layout and structure organization of the overall area, and is used for small-scale style adjustments that do not affect the overall layout; 4. When nesting, it can contain any elements, and block-level elements should not be nested inside.

linkrel="preload" is a technology that optimizes page loading performance and is used to load critical resources in advance. Its core purpose is to prioritize loading of resources that are critical to home screen rendering, such as fonts, key CSS/JS and home screen images. Pay attention to when using: 1. Set the as attribute correctly to specify the resource type; 2. Avoid abuse and prevent excessive bandwidth usage; 3. Ensure that the resources will be actually used, otherwise it will cause waste of requests; 4. Add crossorigin attribute to cross-domain resources. Incorrect writing method such as the lack of the as attribute will cause the preload to be invalid. Rational use can improve page loading efficiency, otherwise it may be counterproductive.

To get started with HTML quickly, you only need to master a few basic tags to build a web skeleton. 1. The page structure is essential, and, which is the root element, contains meta information, and is the content display area. 2. Use the title. The higher the level, the smaller the number. Use tags to segment the text to avoid skipping the level. 3. The link uses tags and matches the href attributes, and the image uses tags and contains src and alt attributes. 4. The list is divided into unordered lists and ordered lists. Each entry is represented and must be nested in the list. 5. Beginners don’t have to force memorize all tags. It is more efficient to write and check them while you are writing. Master the structure, text, links, pictures and lists to create basic web pages.

ShadowDOM is a technology used in web component technology to create isolated DOM subtrees. 1. It allows the mount of an independent DOM structure on ordinary HTML elements, with its own styles and behaviors, and does not affect the main document; 2. Created through JavaScript, such as using the attachShadow method and setting the mode to open; 3. When used in combination with HTML, it has three major features: clear structure, style isolation and content projection (slot); 4. Notes include complex debugging, style scope control, performance overhead and framework compatibility issues. In short, ShadowDOM provides native encapsulation capabilities for building reusable and non-polluting UI components.

❌Youcannotnesttagsinsideanothertagbecauseit’sinvalidHTML;browsersautomaticallyclosethefirstbeforeopeningthenext,resultinginseparateparagraphs.✅Instead,useinlineelementslike,,orforstylingwithinaparagraph,orblockcontainerslikeortogroupmultipleparagraph

TheHTMLdownloadattributeallowsuserstodownloadfilesdirectlyfromalinkbyusingthetag.Toimplementit,adddownloadtotheanchortag,suchasDownloadPDF,orspecifyacustomfilenamelikeDownloadasmy-document.pdf.1.Itworksbestwithsame-originURLsandcommonfiletypeslikePDF

The style placement method needs to be selected according to the scene. 1. Inline is suitable for temporary modification of single elements or dynamic JS control, such as the button color changes with operation; 2. Internal CSS is suitable for projects with few pages and simple structure, which is convenient for centralized management of styles, such as basic style settings of login pages; 3. Priority is given to reuse, maintenance and performance, and it is better to split external link CSS files for large projects.

To embed YouTube videos in a web page, you can directly copy the embedded code provided by YouTube and paste it into the HTML page; 1. Open the target video page and confirm the correct video link; 2. Click "Share" → "Embed" to copy the generated iframe code; 3. Or manually create the iframe tag and set the src to https://www.youtube.com/embed/video ID; 4. It is recommended to use responsive width and add allowfullscreen attributes; 5. Advanced suggestions include using containers to achieve 16:9 ratios, delay loading to improve performance, and pay attention to privacy policy tips.
