Live Preview
A simple site header with title and navigation links:

By the end of this tutorial, you’ll build semantic page headers with logos, navigation, and section introductions.
The HTML <header> tag is a semantic HTML5 element for introductory content at the top of a page or section. This guide covers syntax, comparisons, accessibility, and best practices for beginners.
Wrap header content in <header> tags.
Pair header with nav for primary links.
Use header inside section or article.
Visible landmark vs invisible metadata.
Style site headers with borders and layout.
Understand implicit role for assistive tech.
<header> Tag?The header element (<header>) is a semantic HTML5 tag that defines introductory content for its nearest sectioning ancestor or the page. It typically contains a logo, site navigation, search form, or section heading—content that identifies and introduces what follows.
head is invisible metadata before body. header is visible content inside body. Heading tags (h1–h6) label text hierarchy and often appear inside a header block.
When used as the page header, browsers expose a banner landmark for screen readers. Common child elements include <h1>, <nav>, and <p>.
Enclose introductory content between opening and closing <header> tags, usually at the start of body or inside a section:
<header>
<!-- Your header content goes here -->
</header>header at the top of body, before main.header per page for a clear banner landmark.aria-label on nav (e.g. aria-label="Main").<header> with the invisible <head> metadata element.| Pattern | Code Snippet | Notes |
|---|---|---|
| Site header | <header><h1>Logo</h1><nav>...</nav> | Page-level banner |
| Section header | <section><header><h2>...</h2> | Scoped to the section |
| Main navigation | <nav aria-label="Main"> | Inside page header |
| Landmark role | banner | Implicit for page header |
| Article header | <article><header>...</header> | Title, author, date |
| Tag-specific attrs | None | Global attributes only |
<header> vs <div>Both can wrap top-of-page content visually, but only header carries semantic meaning:
| Feature | <header> | <div> |
|---|---|---|
| Semantic role | Header landmark (banner) | Generic container |
| SEO & a11y | Built-in header semantics | Requires ARIA role manually |
| Scope | Nearest section or page | No implied scope |
| Best for | Logo, site nav, section intro | Non-semantic layout wrappers |
<header> vs <head>These names sound similar but serve completely different roles:
| Feature | <header> | <head> |
|---|---|---|
| Location | Inside body (visible) | Inside html, before body |
| Purpose | Introductory page/section content | Document metadata |
| Visible to users | Yes | No |
| Typical contents | Logo, nav, section title | title, meta, link, script |
<header> vs Heading Tags (h1–h6)The old reference incorrectly conflated header with heading tags. They work together:
| Feature | <header> | <h1>–<h6> |
|---|---|---|
| Element type | Sectioning / landmark container | Heading text labels |
| Role | Groups intro content (nav, logo, title) | Defines content hierarchy |
| Typical usage | <header><h1>Site Name</h1><nav>...</nav></header> | One h1 per page for main topic |
| Related tutorial | This page | See heading tag tutorial |
The <header> tag has no tag-specific attributes. Use global attributes and semantic child elements inside the header:
class / id GlobalCSS hooks for layout, sticky positioning, and branding styles.
class="site-header"aria-labelledby A11yLabels the header landmark when multiple headers exist on one page.
aria-labelledby="site-title"lang GlobalLanguage of header text when it differs from the document.
lang="en"Child elements ContentUse h1–h6, nav, p, and links inside header.
<nav aria-label="Main"><header class="site-header">
<h1 id="logo">My Website</h1>
<nav class="main-nav" aria-label="Main">
<!-- Navigation menu items go here -->
</nav>
</header>Site headers, document structure, and section headers with copy-ready code and live previews.
A simple site header with title and navigation links:
The primary use of <header> is to group a site logo (often an h1) with primary navigation.
<header>
<h1 id="logo">My Website</h1>
<nav class="main-nav" aria-label="Main">
<a href="#home">Home</a>
<a href="#about">About</a>
</nav>
</header>Use <header> for site-wide branding and primary navigation, hero introductions, article titles with bylines, section headings inside long pages, and search bars at the top of a layout. Pair with main and footer for complete page structure.
Define the header of an entire document with logo and navigation before the main content area.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Website</title>
</head>
<body>
<header>
<h1>My Website</h1>
<nav aria-label="Main">
<a href="#">Home</a>
<a href="#">About</a>
</nav>
</header>
<main>
<!-- Main content goes here -->
</main>
</body>
</html>Use <header> within section or article to define subsection introductory content.
<section>
<header>
<h2>Section 1</h2>
</header>
<p>Section content goes here.</p>
</section>Visually distinguish the site header from main content with spacing, borders, and flex layout:
border-bottom Separate from mainpadding Comfortable spacingheader nav Horizontal link rowbackground Dark header bar/* Site header styling */
header.site-header {
padding: 1rem 1.25rem;
border-bottom: 1px solid #e2e8f0;
background: #f8fafc;
}
header.site-header h1 {
margin: 0 0 0.5rem;
font-size: 1.25rem;
}
header nav {
display: flex;
gap: 1rem;
}Live styled header
Semantic headers help all users navigate your page:
banner landmark per page is clearest for screen readers.aria-label="Main" when header and footer both contain nav.h1 in the page header for the site or page topic.header before main in the DOM for logical reading order.Wrap logo, nav, and intro text in header.
Page-level headers map to the banner landmark for assistive tech.
Flex layouts, sticky positioning, and backgrounds visually brand the top of the page.
Users and search engines understand where introductory content lives.
The <header> element is fully supported in all modern browsers and Internet Explorer 9+.
From legacy Internet Explorer to the latest mobile browsers — header is a safe HTML5 building block for page structure.
Bottom line: Ship semantic page headers with confidence. The <header> element is safe to use in every production environment today.
Mastering the HTML <header> tag is key to creating well-structured and accessible web content. Whether branding your site or introducing a section, header provides semantic meaning that plain div elements cannot.
Use one clear page header before main, label navigation for accessibility, and style the block with CSS so users immediately recognize your site identity.
header for logo, site nav, and section introductionsmain in the DOMaria-label on header nav elementsh1 in the page header when appropriatemain and footer for full page structureheader with invisible head metadataheader with heading tags (h1–h6)headerheader with a plain div<header>Bookmark these before you ship — they’ll keep your page structure semantic and accessible.
<header> is intro content in body.
Pair with labeled nav.
Metadata lives in head.
Headings go inside header.
StructureImplicit landmark for page header.
AccessibilityHTML5 semantic element, IE9+.
Compatibilityhead holds invisible metadata before body. header is visible introductory content inside body.header is a container landmark. h1 is a heading tag that often appears inside a header to label the site or section title.section or article introduces that block only — such as a section title or article byline.class, id, and aria-labelledby.header is an HTML5 semantic element with full support in all modern browsers and IE 9+.Practice logo, navigation, and section headers in the interactive HTML editor.
6 people found this page helpful