HTML <header> header tag


The <header> tag in HTML is used to define a header section for a document or a section of a document. It is a semantic element that typically contains introductory content or navigational aids, and helps to structure a webpage or section into logical parts.

Syntax:

<header> <!-- Header content goes here --> </header>

Key Characteristics:

  1. Purpose:

    • Introduction: The <header> tag often includes introductory content or key information about the document or section it is associated with.
    • Navigation: It commonly contains navigational elements such as menus, links, or logos.
  2. Content:

    • The <header> tag can contain a variety of content, including:
      • Headings (<h1>, <h2>, etc.): Used to provide titles or subtitles.
      • Navigation Menus (<nav>): For site-wide or section-specific navigation.
      • Logos (<img>): Displaying branding or site identification.
      • Introduction: Short descriptions or introductory text.
      • Contact Information: Details like phone numbers or email addresses.
  3. Usage:

    • Page Header: Defines the header for the entire webpage, usually placed at the top of the document.
    • Section Header: Defines headers for specific sections of a webpage, such as an article or a sidebar.
  4. Styling:

    • The <header> tag can be styled using CSS to suit the design of the webpage. This includes setting background colors, text alignment, padding, and more.

Example Usage:

Basic Page Header:

<header> <h1>Welcome to My Website</h1> <nav> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#services">Services</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> </header>

In this example:

  • The <header> contains a main heading (<h1>) and a navigation menu (<nav>) with links.

Section Header:

<section> <header> <h2>Chapter 1: Introduction to HTML</h2> </header> <p>This chapter covers the basics of HTML...</p> </section>

In this example:

  • The <header> is used within a <section> to provide a heading specific to that section of content.

Accessibility and SEO:

  • Accessibility: The <header> tag improves accessibility by clearly defining sections of a page, making it easier for screen readers and assistive technologies to understand the layout and navigation. It helps users with disabilities to quickly identify and navigate to important content.
  • SEO: The <header> tag contributes to SEO by improving the structure of the webpage. Including relevant headings and navigation links in the <header> helps search engines understand the importance of different sections and can improve the site's indexability and ranking.