Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App

HTML header Tag

Last Updated : 03 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The <header> tag is a semantic HTML element that is used to define the introductory or navigational content of a webpage or a section. Typically, a header contains elements like:

  • The website or page title
  • Logo or branding
  • Navigation menus
  • Search bar
  • Any introductory information relevant to the page or section

Note: Header tag cannot be placed within a <footer>, <address>, or another <header> element.

Syntax:

<header> ...</header>

HTML <header> tag Example

Example 1:

In this example, the <header> tag is used inside the <article> element to define introductory content for that article.

HTML
<!DOCTYPE html> <html>  <body style="font-size: 25px;">     <h1 style="color: green;">GeeksforGeeks</h1>     <h3>HTML Header Tag</h3>     <hr>     <article>         <header>             <h3 style="color: green;">                 GeeksforGeeks Learning             </h3>             <p>Posted by GFG</p>             <p>                 A Computer Science portal for geeks.                 It contains well written, well thought <br>                 and well explained computer science and                 programming articles.             </p>         </header>     </article> </body>  </html> 

Output:
Screenshot-2023-12-14-154747

  • The <header> tag here contains:
    • <h3>: 'GeeksforGeeks Learning'
    • <p> (Paragraph): 'Posted by GFG'
    • Another <p> (Paragraph): 'A Computer Science portal for geeks' - along with more information.

Important: The <header> is not just for the main page header (like a site title), but it can also be used for each article or section to provide the essential context — such as the article’s title, author, and a short description.

HTML Header Tag Attributes

The <header> tag itself doesn't have attributes unique to it. However, it supports most of the global attributes of HTML, such as id, class, style, role, lang, data-*, and tabindex.

Additionally, you can apply styling to control its behavior and appearance using CSS. The <header> tag also supports Event Attributes in HTML, allowing you to add interactivity, such as onclick, onmouseover, and others, to enhance user experience.

Example 2:

HTML
<!DOCTYPE html> <html>  <body>     <h1>GeeksforGeeks</h1>     <h3>HTML Header Tag</h3>      <!--HTML header tag starts here-->     <header>         <h1>This is the heading.</h1>         <h4>This is the sub-heading.</h4>          <p>This is the metadata.</p>     </header>     <!--HTML header tag ends here--> </body>  </html> 

Output:

HTML <header> Tag

In this example:

  • Main content: The document has a primary title (<h1>GeeksforGeeks) followed by a secondary heading (<h3>HTML Header Tag).
  • Header tag: Inside the <header>, there’s a primary heading (<h1>) and a subheading (<h4>) along with a paragraph (<p>).

Example 3:

This HTML code demonstrates the usage of the <header> tag to structure a navigation section of a webpage.

HTML
<!DOCTYPE html> <html>  <body>     <h1>GeeksforGeeks</h1>     <h3>HTML Header Tag</h3>      <!--HTML header tag starts here-->     <header>         <a href= "https://www.geeksforgeeks.org/fundamentals-of-algorithms/">             Algo</a> |         <a href= "https://www.geeksforgeeks.org/data-structures/">             DS</a> |         <a href= "https://www.geeksforgeeks.org/category/program-output/">             Languages</a> |         <a href= "https://www.geeksforgeeks.org/company-interview-corner/">             Interview</a> |         <a href= "https://www.geeksforgeeks.org/student-corner/">             Students</a> |         <a href= "https://www.geeksforgeeks.org/gate-cs-notes-gq/">             Gate</a> |         <a href= "https://www.geeksforgeeks.org/articles-on-computer-science-subjects-gq/">             CS Subjects</a> |         <a href= "https://www.geeksforgeeks.org/quiz-corner-gq/">             Quizzes</a>         <div class="search-bar">           <input type="text" placeholder="Search products...">           <button>Search</button>         </div>      </header>     <!--HTML header tag ends here-->    </body>  </html> 

Output:

In this example:

  • The navigation links (<a> tags) within the <header> allow users to quickly jump to different sections of the site. These links are separated by a pipe (|) symbol for readability.

Key Points to Remember About the <header> Tag

  • Multiple headers: You can have multiple <header> tags on a page. For example, each section or article can have its own <header>, but there should only be one site-wide <header>.
  • Not just for titles: While the <header> tag often contains a heading (<h1>, <h2>), it can also hold other elements like navigation links (<nav>), search bars, or introductory text.
  • Keep it clear: The <header> tag should contain introductory content. It’s not meant to hold all content; its purpose is to help introduce or navigate the content.

Supported Browsers

  • Google Chrome
  • Edge 
  • Firefox
  • Opera
  • Safari

S

Shubrodeep Banerjee
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML5
  • HTML-Tags

Similar Reads

    HTML DOCTYPE Declaration
    HTML DOCTYPE (Document Type Declaration) is an instruction that appears at the beginning of an HTML document, before the <html> tag.Its primary role is to tell the web browser which version of HTML the page is written in, ensuring that the browser renders the content correctly. It is not an HT
    4 min read
    HTML abbr Tag
    The <abbr> tag in HTML is used to represent abbreviations and provides additional information about them through the title attribute, which displays a tooltip when hovered over. It helps improve accessibility and SEO by offering context for the abbreviated text.It makes text clearer by explain
    3 min read
    HTML acronym Tag
    The HTML <acronym> tag was used to define an acronym, providing a way to identify and explain abbreviated terms in web content. However, it's deprecated in favor of <abbr>, which serves the same purpose but is more semantically correct.Syntax: <acronym title=""> Short Form </acr
    2 min read
    HTML < address> Tag
    The <address> tag in HTML is used to define contact information for the author or owner of a document or an article. It is typically used for information such as an address, email, or phone number.The <address> element is a block-level element by default.The content inside <address
    3 min read
    HTML a Tag
    The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. This attribute determines where the user is directed upon clicking the link.HTML<a href="http
    2 min read
    HTML applet Tag
    The applet tag in HTML was used to embed Java applets into any HTML document. The <applet> tag was deprecated in HTML 4.01, and its support has been completely discontinued starting from HTML 5. Alternatives available in HTML 5 are the <embed> and the <object> tags. Some browsers s
    2 min read
    HTML area Tag
    This <area> tag is used in an HTML document to map a portion of an image to make it clickable by the end user. This specifies the location and size of the active region on an image, which can be clicked. Clicking on areas with href attributes directs to a specified URL or action.html<!DOCTY
    3 min read
    HTML article Tag
    The HTML <article> tag defines a self-contained, independent piece of content like a blog post, news article, or comment. It is designed for content that can be independently distributed, shared, or reused, providing semantic meaning to the content.This tag is introduced in HTML5.HTML<!DOCT
    3 min read
    HTML aside Tag
    The <aside> tag is used to describe the main object of the web page more shortly like a highlighter. It identifies the content that is related to the primary content of the web page but does not constitute the main intent of the primary page. The <aside> tag contains mainly author inform
    2 min read
    HTML5 < audio> Tag
    The <audio> tag in HTML5 is used to embed audio content on a webpage. It allows you to play audio files like MP3, OGG, or WAV directly in the browser. The <audio> element provides attributes for controlling playback, such as play, pause, and volume.Using the <source> element enable
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences