HTML <header> Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

Definition and Usage

The <header> element represents introductory content for a page or a section — typically a heading, logo, navigation, search, slogan, or byline.

A top-level page <header> (not inside <article>, <section>, <nav>, <aside>, or <main>) acts as the site banner landmark. Nested in those sections, it introduces that section only. Do not confuse it with <head> (document metadata).

Baseline · Widely available.

Not deprecated. Stable across browsers since about July 2015 (and earlier as HTML5).

Nesting rule.

Do not put <header> or <footer> inside a <header>, and do not nest <header> inside <footer> or <address>.

HTML Syntax

syntax.html
<header> introductory content</header>

Both start and end tags are required. Content is flow content, but not another <header> or <footer>.

Attributes

The <header> element has no element-specific attributes — only global attributes.

AttributeDescriptionNotes
None specificNo dedicated attributes on <header> itself.Use class / id for layout and styling hooks.

Global Attributes

The <header> tag also supports the Global Attributes in HTML.

Live Preview

Switch between a site banner <header> and an article <header>.

Top-level headers are banner landmarks; nested ones introduce a section.

Preview

CodeToFun

Site-wide header (banner landmark)

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Site Banner Header

A top-level <header> with a title and navigation.

HTML
<header>
  <h1>CodeToFun</h1>
  <nav aria-label="Primary">
    <a href="/">Home</a>
    <a href="/html">HTML</a>
    <a href="/css">CSS</a>
  </nav>
</header>
Try It Yourself

How It Works

  1. Open <header> near the top of the body (outside main/article if it is the site banner).
  2. Add a site title with a heading (often <h1> for the home page brand).
  3. Include <nav> for primary links when needed.
  4. Close the tag. Assistive tech can treat this as the banner landmark.

Example 2 — Article Header

Nest <header> inside <article> for the title and byline.

HTML
<article>
  <header>
    <h2>The Planet Earth</h2>
    <p>
      Posted on
      <time datetime="2017-10-04">4 October 2017</time>
      by Jane Smith
    </p>
  </header>
  <p>We live on a planet that is blue and green.</p>
</article>
Try It Yourself

How It Works

  1. Wrap the piece in <article>.
  2. Put intro metadata (title, date, author) in <header>.
  3. Keep the body after the header as normal paragraphs.
  4. This header is not a banner — it only introduces the article.

Example 3 — Section Header

Introduce a <section> with a heading and short summary.

HTML
<section>
  <header>
    <h2>Getting started</h2>
    <p>Install the tools, then write your first page.</p>
  </header>
  <p>Create an index.html file in your project folder.</p>
</section>
Try It Yourself

How It Works

  1. Open <section> for a themed block of content.
  2. Add <header> with the section heading and optional blurb.
  3. Follow with the section body.
  4. Repeat the pattern for other sections that need a clear intro.

Example 4 — header vs head (Do Not Mix Them)

<head> is for metadata; <header> is visible page chrome.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My site</title>
</head>
<body>
  <header>
    <h1>My site</h1>
  </header>
  <main>
    <p>Page content goes here.</p>
  </main>
</body>
</html>
Try It Yourself

How It Works

  1. <head> holds title, charset, stylesheets — not shown as page chrome.
  2. <header> lives in <body> and is visible to users.
  3. Put the brand / nav in <header>, not in <head>.
  4. Main content usually follows in <main>.

Edge Cases & Pitfalls

Most header mistakes confuse head, nest landmarks badly, or put footers inside headers.

names

header ≠ head ≠ headings

head is metadata. h1–h6 are headings. header is an intro container that often includes a heading.

nesting

No header/footer inside header

Also avoid nesting header in footer or address. Keep the intro block simple.

a11y

Banner only at the top level

Inside article/section/nav/aside/main, header is not a banner landmark and should not be labeled as one.

count

Multiple headers are fine

One site banner plus article headers is normal. Do not force everything into a single header.

Browser Support

The <header> element is core HTML sectioning/flow content in every modern browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<header>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera all support the element. Landmark behavior follows the nesting rules in the accessibility section above.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer 9+
Supported
<header> Widely supported

Bottom line: Safe to use for page and section intros. Keep head for metadata, and respect nesting rules so landmarks stay clear.

Key Takeaways

  • Role: <header> groups introductory content for a page or section.
  • Banner: top-level headers map to the site banner landmark.
  • Not head: document metadata stays in <head>.
  • Nesting: no header/footer inside header; pair with footer for page chrome.

One line: use <header> for intros — site banner at the top, or a local intro inside an article/section.

Default CSS Settings

Typical user-agent styling for header:

default.css
header {
  display: block;
}

Layout (flex, sticky bars, backgrounds) comes from your CSS — the element itself is only semantic structure by default.

Frequently Asked Questions

The header element holds introductory content for a page or a section — often a heading, logo, navigation, search, or byline. It is not the same as the document <head>.
No. <head> is metadata for the document (title, links, scripts). <header> is visible introductory content in the page body.
No. You can have a site-wide header and also headers inside articles or sections. Nested headers introduce that section, not another page banner.
When it is not nested in article, aside, main, nav, or section (or matching ARIA roles), it maps to the banner landmark — typically the site header.
No. A header must not contain header or footer descendants, and must not be nested inside address, footer, or another header.
No, but a heading is common and helpful. Logo, nav, or search alone can also make a valid header.

Next: heading

Learn the HTML heading elements h1 through h6 for document outline.

heading tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful