HTML <header> Element

Publish in HTML Tutorial el 24/05/2025 15:05

The <header> element represents introductory content for its nearest ancestor sectioning content or sectioning root element. It typically contains headings (h1-h6), logos, search forms, navigation, or author information. Unlike the <head> element which contains metadata, the <header> is visible content.


Key characteristics:

  • Can be used multiple times on a page (for different sections)
  • Does not create a new section in the outline
  • Often contains the section's heading (h1-h6)
  • Can contain navigation, logos, or other introductory content


Basic Syntax

Here's the basic structure of a <header> element:


Examples of <header> Usage

Example 1: Basic Page Header

A simple header containing a title and subtitle:

Play Code


Example 2: Header with Navigation

A common pattern combining navigation within the header:

Play Code


Example 3: Article Header

Header used within an article element:

Play Code


Example 4: Dynamic Header with JavaScript

Header that changes based on user interaction:

Play Code


Example 5: Sticky Header with JavaScript

A header that sticks to the top when scrolling:

Play Code


Tips and Tricks

  • Semantic Nesting: Always place your <h1>-<h6> headings inside the <header> when they represent the heading for that section.
  • Multiple Headers: You can use multiple <header> elements in one document - one for the page and others for each <article> or <section>.
  • Accessibility: Screen readers can identify <header> content, improving navigation for users with disabilities.
  • SEO Benefit: Search engines give more weight to content within <header> elements.
  • Styling: Use CSS to make your header stand out with background colors, borders, or fixed positioning.


Common Mistakes to Avoid

  • Don't confuse <header> with <head> - they serve completely different purposes.
  • Avoid placing footer-type content (like copyright information) in the header.
  • Don't overuse - not every section needs a header if it doesn't have introductory content.
  • Avoid making headers too tall on mobile devices where screen space is limited.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...