HTML header Element

HTML <header> Element: Introductions With Meaning

Every story has a beginning — and in HTML, that beginning often lives in a <header>. This semantic element represents the introductory content of a page or a section. It's not just about visual design — it's about giving structure and meaning to where things begin.

Purpose of <header>

The <header> element is used to group introductory content — like titles, logos, navigation, and brief summaries. It can be used once at the top of the page or within individual sections or articles.

Think of it as the handshake of your content.

Basic Syntax

<header>
  <h1>Fruit Blog</h1>
  <nav>
    <a href="#apple">Apple</a>
    <a href="#banana">Banana</a>
  </nav>
</header>
Fruit Blog  
[ Apple | Banana ]

This header introduces the page and includes navigation for fruit-related topics.

Where Can You Use <header>?

  • At the top of the entire document — introducing the whole page
  • Inside <article> or <section> — as a local heading

Example: Section with Header

<section>
  <header>
    <h2>Cherry Facts</h2>
    <p>Everything you need to know about cherries.</p>
  </header>
  <p>Cherries are small, round, and rich in antioxidants...</p>
</section>

This use clearly introduces the section without affecting the main page header.

Difference Between <header> and <head>

These two are often confused. Here’s a quick distinction:

| Element | Purpose | |---------------|---------------------------------------| | <head> | Contains metadata, links, scripts | | <header> | Contains visible page/section intro |

Accessibility and Semantics

<header> helps screen readers and assistive technologies understand the structure of your content. It improves navigability for users with disabilities by grouping related introductory content.

Best Practices:

  • Use only one <header> per section
  • Include <h1> to <h6> inside headers to clarify hierarchy
  • Avoid placing <header> inside a <footer> or <address>

Real-World Example: Full Page with <header>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Fruit World</title>
</head>
<body>

  <header>
    <h1>Welcome to Fruit World</h1>
    <nav>
      <a href="#apple">Apple</a> |
      <a href="#banana">Banana</a> |
      <a href="#cherry">Cherry</a>
    </nav>
  </header>

  <main>
    <section id="apple">
      <header>
        <h2>Apple Section</h2>
      </header>
      <p>Apples are crispy and sweet.</p>
    </section>
  </main>

</body>
</html>
Welcome to Fruit World  
[ Apple | Banana | Cherry ]

Apple Section  
Apples are crispy and sweet.

Summary

The <header> element creates a meaningful introduction for content. You’ve learned how to:

  • Use <header> for pages, articles, and sections
  • Include navigation and headline content
  • Improve accessibility and content clarity

Check your understanding 1

What is the main purpose of the <header> element in an HTML document?
Choose one answer. You can try again.

Answer and explanation

To contain introductory content or navigational links

The <header> element typically contains introductory information or navigation links related to the section or page, helping structure content semantically.

Check your understanding 2

Multiple <header> elements can be used within a single HTML page to define headers for different sections.
Choose one answer. You can try again.

Answer and explanation

True

You can use multiple <header> elements to represent headers for different parts of the page, such as the site header and individual section headers.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. <h1> to <h6> headings
  2. <nav> navigation
  3. <footer>
  4. <img> logos or branding
Which of the following elements are commonly found inside a <header> element?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 2 and 4

Headers often include headings to identify the section, navigation links for quick access, and images such as logos for branding. The footer is a separate element and usually not inside a header.

Check your understanding 4

How does using the <header> element improve accessibility?
Choose one answer. You can try again.

Answer and explanation

By helping screen readers identify the start of content sections

Semantic elements like <header> provide meaningful landmarks that assistive technologies use to help users navigate content more efficiently.

Check your understanding 5

The <header> element is mandatory in every HTML document.
Choose one answer. You can try again.

Answer and explanation

False

While recommended for semantic clarity, the <header> element is not required in all HTML documents.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. Place site title or logo inside the header
  2. Use <header> only once per page
  3. Include navigation menus inside the header
  4. Nest <header> within <section> or <article> for section headers
Which of the following are best practices when using the <header> element?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3 and 4

Using headers for main and sectional headings, including logos and navigation menus, improves structure and accessibility. It is acceptable to use multiple headers within different sections.

What’s Next?

Up next: we’ll explore the <footer> element — the closing act that wraps up content meaningfully and semantically.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML footer Element →