Your Search Bar For Shrewd Tips

How To Close Header


If you are learning HTML, knowing how to close a header is a small detail that prevents confusing layout and markup problems. The short answer is to end the element with the closing tag </header>. However, where that tag belongs depends on what the header contains and how it fits into the rest of your page.

This guide explains how to close a header in HTML, how to recognize the header’s correct ending point, and what to do if you mean hiding or collapsing a website header instead. You will also learn how to avoid common mistakes and check that your page structure is clear, accessible, and easy to maintain.

What Does It Mean to Close a Header?

In HTML, a header is a semantic element that groups introductory content for a page or a section. Its opening tag is <header>, and its closing tag is </header>. The closing tag tells the browser that the header element has ended and that the content that follows belongs to a different part of the document.

A basic header might contain a logo and a navigation menu. The markup starts with the opening tag, includes the header content, and finishes with the closing tag:

<header>
  <a href="/">Example Site</a>
  <nav aria-label="Main navigation">
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
  </nav>
</header>

<main>
  <h1>Welcome</h1>
  <p>Page content starts here.</p>
</main>

The key point is that the header closes after all the content intended to belong to it and before the next major section begins. In this example, the page’s main content is outside the header because the closing tag appears before <main>.

How to Close a Header in HTML

To close a header, type a forward slash after the opening angle bracket, followed by the element name: </header>. Place it after the header’s last child element. HTML tags are not case-sensitive, but lowercase tags are the standard convention and make code easier to read.

Use this simple pattern:

<header>
  Header content goes here.
</header>

Do not add attributes to the closing tag. For example, </header class="site-header"> is not valid HTML. Put any class or other attribute on the opening tag instead:

<header class="site-header">
  <h1>Example Site</h1>
</header>

Unlike some HTML elements, a header is not a void element. It cannot be left open or self-closed. You should not write <header /> as a replacement for a proper opening and closing tag. Always include both <header> and </header>.

Where Should the Closing Header Tag Go?

The closing tag belongs immediately after the final piece of content that functions as part of that header. That content could include a site title, a logo, a search form, introductory text, or navigation. The right stopping point is determined by the purpose of the section—not by how much content you can fit inside the element.

For example, if the header contains a logo and navigation, close it after the navigation. Then begin the main content as a separate element:

<header>
  <h1>Garden Notes</h1>
  <nav aria-label="Main navigation">
    <a href="/plants">Plants</a>
    <a href="/guides">Guides</a>
  </nav>
</header>

<main>
  <article>
    <h2>Choosing a Garden Location</h2>
    <p>Start by observing the light in your garden.</p>
  </article>
</main>

If a piece of content is the main subject of the page, it usually belongs in <main>, not in the site header. Keeping these areas separate creates a more meaningful document outline and makes the page easier to understand for browsers, assistive technology, and other developers.

Site Headers and Section Headers

The <header> element is not limited to the top of an entire website. It can introduce the whole page or a particular section, such as an article. A page may therefore have a site header and an article header, each with its own closing tag.

<header>
  <h1>Travel Journal</h1>
  <nav aria-label="Main navigation">
    <a href="/destinations">Destinations</a>
  </nav>
</header>

<main>
  <article>
    <header>
      <h2>A Weekend in Lisbon</h2>
      <p>Published on June 12</p>
    </header>

    <p>The trip began with a walk through the old town.</p>
  </article>
</main>

In this example, the first </header> closes the site-wide header. The second closes the article header. Each opening tag must be matched with the correct closing tag, and the tags should be nested in the proper order. A header element must not be placed inside another header element. A section or article can have its own header, but that header should be a separate element in the document structure.

Header Is Not the Same as Head

A frequent source of confusion is the difference between <header> and <head>. They look similar, but they serve very different purposes. The <head> element contains page information such as the title, metadata, and links to stylesheets. It is not the visible banner at the top of a page.

The <header> element is part of the page body and contains visible introductory content. It belongs inside <body>. A simplified page structure looks like this:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example Page</title>
  </head>
  <body>
    <header>
      <h1>Example Site</h1>
    </header>

    <main>
      <p>Page content goes here.</p>
    </main>
  </body>
</html>

The <head> section does not use a header closing tag. Close it with </head>. Close the visible header with </header>. Using the right element and matching closing tag helps avoid errors and makes your intent clear.

Common Mistakes When Closing a Header

Most header markup errors come from forgetting a closing tag, putting it in the wrong place, or confusing HTML structure with visual design. Watch for these common problems:

  • Forgetting the closing tag: Leaving <header> open can cause later content to be interpreted as part of the header.
  • Closing it too early: If the tag appears before the navigation or other header content, that content may end up outside the header unintentionally.
  • Closing it too late: If the main page content is placed before </header>, the page structure becomes misleading.
  • Using a self-closing tag: <header /> does not correctly replace an opening tag and a closing tag.
  • Mixing up header and head: The visible page header belongs in the body; document metadata belongs in the head.
  • Nesting header elements: Use a header for the page or a section, but do not place one header element inside another.

Indentation can help you spot these issues. Indent the content inside the opening tag, then line up </header> with <header>. While indentation does not change how a browser reads HTML, it makes missing or misplaced tags much easier to notice.

Does Closing a Header Hide It?

No. The closing tag only ends the header element in the HTML document. It does not hide the header, close a window, or make a navigation bar disappear from the screen. If you want to hide or collapse a visible header, you need a styling or interaction method, such as CSS or JavaScript.

For example, a CSS class can hide an element visually:

.site-header.is-hidden {
  display: none;
}

That rule changes the element’s display when the relevant class is applied. It does not replace the need for a closing HTML tag. Your markup should still have a complete header element, such as <header class="site-header is-hidden">...</header>. If a header is meant to open and close in response to a button, consider whether a disclosure pattern is appropriate and ensure the button communicates its state to users.

How to Check That Your Header Is Closed Correctly

After writing your markup, inspect the structure rather than relying only on how it looks in a browser. Browsers often try to recover from invalid HTML, so a page may appear normal even when a tag is missing or misplaced.

  • Find every <header> opening tag and confirm it has a matching </header>.
  • Check that each closing tag follows the final content of its header.
  • Make sure the main content begins after the page-level header has closed.
  • Use consistent indentation to make nested sections easy to follow.
  • Run the page through an HTML validator to find unclosed or incorrectly nested elements.
  • Review the page with a screen reader or accessibility inspection tool if the header contains important navigation.

When working in a code editor, HTML syntax highlighting and auto-formatting can also help. Some editors show a matching opening tag when you select a closing tag. These tools are useful, but they do not decide where the header should end; that choice still depends on the intended structure of your page.

Best Practices for a Clear HTML Header

Use the header element for meaningful introductory content rather than as a generic container for anything at the top of the screen. A site header commonly contains branding and primary navigation. An article header may contain a title, author, or publication date. Keep unrelated page content outside these elements.

Use heading levels to express the content hierarchy. A page’s main title is often an <h1>, while an article title within a page may use a level that fits the surrounding structure. The <header> element does not create a heading by itself; it simply groups content. Include a clear heading when the section needs one.

For navigation, use a <nav> element and give it an accessible label when the page has more than one navigation area. For example, a site might have “Main navigation” and “Footer navigation.” These choices help visitors understand the structure, while a correctly placed </header> keeps the boundaries of the header clear.

Conclusion

To close a header in HTML, add the matching </header> tag after the header’s final piece of content. Do not leave the element open or use a self-closing tag. Keep the page’s main content outside the site header, match each opening tag to its own closing tag, and remember that <header> is different from <head>.

If your goal is to make a visible header disappear, closing the HTML element is not the solution; use CSS or an appropriate interactive control instead. With correctly structured markup and a clear understanding of what the closing tag does, you can build headers that are easier to maintain and more accessible to your visitors.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →