When building a website, structuring your content effectively is crucial, not just for aesthetics but also for search engine optimization (SEO) and accessibility. A common question that arises is: In HTML5, should the main navigation be inside or outside the <header> element? This decision impacts how search engines understand your site’s structure and how easily users can navigate your content. The <header> element, introduced in HTML5, is designed to contain introductory content or a set of navigational links. However, best practices often dictate that the main navigation, which provides access to the core sections of your website, may be more appropriately placed after the header. Understanding the nuances of semantic HTML and how it affects user experience and SEO is essential for modern web development. Let’s explore the arguments for both approaches and delve into why one typically stands out as the preferred method for structuring your website’s primary navigation.
Understanding the <header> Element
The <header> element in HTML5 serves as a container for introductory content. This often includes a website’s logo, title, and sometimes a brief description or tagline. Think of it as the introductory section of a document, webpage, or even an article within a page. The <header> tag helps to define the structure of a web page, making it easier for both users and search engines to understand the content’s organization. According to the W3C specification, a <header> is intended to contain “introductory content,” which could reasonably include a navigation section, but the context and scope of that navigation are key.
While it’s tempting to include the entire main navigation inside the <header> element, this approach can sometimes dilute the header’s primary purpose, especially if the navigation is extensive. A large navigation menu can clutter the header, making it less visually appealing and potentially hindering the user experience. Remember that the <header> element can appear multiple times on a page, such as within individual <article> elements, each with its own local navigation. Therefore, it’s important to distinguish between site-wide navigation and navigation that is specific to a section or article.
Consider a news website. The site’s main <header> might contain the logo, site name, and a smaller navigation for account management or site-wide settings. The main navigation, providing links to categories like “Politics,” “Sports,” and “Technology,” could then be placed immediately after the <header>, ensuring it’s prominent but doesn’t overwhelm the introductory content. This separation maintains a clear distinction between the site’s branding and its core navigational structure.
The Case for Placing Navigation Outside the <header>
Placing the main navigation outside the <header> element, typically directly after it within the <body> tag, offers several advantages. First, it allows for a cleaner and more focused <header> element, dedicated to branding and introductory information. Second, it provides greater flexibility in terms of styling and positioning the navigation menu. You can easily create a sticky navigation bar that remains visible as the user scrolls, a design pattern that is increasingly common and expected on modern websites. Third, it allows screen readers to easily identify the main navigation, improving accessibility.
Here’s a featured snippet-optimized paragraph: Separating the main navigation from the <header> element enhances website accessibility, allows for cleaner design, and offers greater control over navigation positioning and styling. By placing it directly after the <header> within the <body>, developers can implement features like sticky navigation while keeping the <header> focused on branding and introductory content. This separation improves both the user experience and the semantic structure of the webpage.
Furthermore, placing the navigation outside allows for more complex navigation structures that might not fit neatly within the header’s layout. Dropdown menus, mega menus, and other advanced navigation patterns can be implemented more easily when the navigation is not constrained by the header’s boundaries. Consider the complexity of an e-commerce website’s navigation, with numerous product categories and subcategories. Placing this entire structure inside the header could make it cumbersome and difficult to manage. “Semantic HTML is about giving meaning and structure to your content, making it more understandable for both users and machines,” says Eric Meyer, a renowned web standards advocate [Eric Meyer’s Website]. This separation adheres to that principle.
Best Practices for Navigation Placement
While there’s no hard and fast rule, the prevailing best practice leans towards placing the main navigation outside the <header> element. This approach offers a cleaner separation of concerns, improved styling flexibility, and enhanced accessibility. However, the specific implementation will depend on the website’s design, content, and overall user experience goals. Regardless of where you place your navigation, ensure it is easily discoverable, clearly labeled, and provides a logical pathway through your website’s content.
When deciding where to place your main navigation, consider these key factors:
- Website Complexity: For simple websites with minimal navigation, placing it inside the <header> might be acceptable.
- Design Requirements: If the design calls for a specific header layout that integrates the navigation seamlessly, it might be necessary to include it within the <header>.
- Accessibility: Ensure that the navigation is accessible to users with disabilities, regardless of its placement. Use ARIA attributes appropriately.
Remember to use semantic HTML elements like <nav> to wrap your navigation, regardless of whether it’s inside or outside the <header>. The <nav> element signals to screen readers and search engines that the content within is intended for navigation purposes. Also, consider the mobile experience. Ensure your navigation is responsive and easily accessible on smaller screens, often through a “hamburger menu” or similar mobile-friendly design pattern. You can find excellent resources and guidance on responsive navigation design from sources like Mozilla Developer Network (MDN).
Implementing Navigation Outside the <header>: A Step-by-Step Guide
To illustrate how to implement navigation outside the <header> element, consider this step-by-step approach:
- Create the <header> element: Add your logo, site title, and any other introductory content within the <header> tag.
- Create the <nav> element: Immediately after the <header>, create a <nav> element to contain your main navigation links.
- Add navigation links: Use <ul> and <li> elements to create an unordered list of links within the <nav> element. Each <li> should contain an <a> tag with the appropriate href attribute.
- Style the navigation: Use CSS to style the <nav> element and its child elements to achieve the desired look and feel.
- Test accessibility: Use a screen reader to ensure that the navigation is accessible to users with disabilities.
Here’s an example of the basic HTML structure:
<header> <img src="logo.png" alt="Website Logo"> <h2>My Awesome Website</h2> </header> <nav> <ul> <li><a href="">Home</a></li> <li><a href="">About</a></li> <li><a href="">Services</a></li> <li><a href="">Contact</a></li> </ul> </nav>
- Is it wrong to put navigation inside the <header>?
- Not necessarily. For simpler sites, it can be acceptable. However, placing it outside often provides more flexibility and better semantic structure.
- What if I have multiple navigation menus?
- Use the <nav> element to wrap each navigation menu, and ensure each has a clear purpose. Consider using ARIA landmarks to further clarify roles.
- How does this affect SEO?
- Proper semantic structure, including the correct use of <header> and <nav> elements, helps search engines understand your website's content and improve its ranking. Also, a good navigational structure helps users find what they are looking for, which can also improve SEO. Learn more [about website SEO](https://courthousezoological.com/n7sqp6kh?key=e6dd02bc5dbf461b97a9da08df84d31c).
- Does this apply to <header> elements within <article> tags?
- Yes, the same principles apply. The <header> within an <article> should primarily contain introductory content for that specific article, while the main site navigation remains separate.
Question & Answer :
In HTML5, I know that <nav> can be used either inside or outside the page’s masthead <header> element. For websites having both secondary and main navigation, it seems common to include the secondary navigation as a <nav> element inside the masthead <header> element with the main navigation as a <nav> element outside the masthead <header> element. However, if the website lacks secondary navigation, it appears common to include the main navigation in a <nav> element within the masthead <header> element.
If I follow these examples, my content structure will be based on the inclusion or exclusion of secondary navigation. This introduces a coupling between the content and the style that feels unnecessary and unnatural.
Is there a better way so that I’m not moving the main navigation from inside to outside the masthead <header> element based on the inclusion or exclusion of secondary navigation?
Main and Secondary Navigation Example
<header> <nav> <!-- Secondary Navigation inside <header> --> <ul> <li></li> </ul> </nav> <h1>Website Title</h1> </header> <nav> <!-- Main Navigation outside <header> --> <ul> <li></li> </ul> </nav>
OnlineDegrees.org is an example site that follows the above pattern.

Main Only Navigation Example
<header> <h1>Website Title</h1> <nav> <!-- Main Navigation inside <header> --> <ul> <li></li> </ul> </nav> </header>
Keyzo.co.uk is an example site that follows the above pattern.

Excerpts from Introducing HTML5 β Added on 02-Feb-11, 7:38 AM
Introducing HTML5 by Bruce Lawson and Remy Sharp has this to say about the subject:
The header can also contain navigation. This can be very useful for site-wide navigation, especially on template-driven sites where the whole of the
<header>element could come from a template file.Of course, it’s not required that the
<nav>be in the<header>.If depends largely on whether you believe the site-wide navigation belongs in the site-wide header and also pragmatic considerations about ease of styling.
Based on that last sentence, it appears that Bruce Lawsonβauthor of the chapter those excerpts are fromβadmits that “pragmatic considerations about ease of styling” yield a coupling between the content and the style.
It’s completely up to you. You can either put them in the header or not, as long as the elements within them are internal navigation elements only (i.e. don’t link to external sites such as a twitter or facebook account) then it’s fine.
They tend to get placed in a header simply because that’s where navigation often goes, but it’s not set in stone.
You can read more about it at HTML5 Doctor.