HTML header Tag

HTML header Tag

While making a website, one of the most important tasks is structuring or organizing your content, because this helps in search engine optimization of your website. That’s the place where semantic tags in HTML come into play. Among many semantic elements in HTML, the <header> tag plays an important role in creating a better layout. In this blog, you will learn everything about the <header> tag in HTML and how to use it with examples and best practices

Table of Contents:

What is HTML?

HTML stands for Hypertext Markup Language. It is defined as the markup language that is used to create the structure of web pages. It is used to add video, text, and links to webpages.

What are Semantic Tags?

The word “Semantic” refers to meaning. Semantic tags in HTML are the tags that clearly define their purpose to both the developer and the browser. There are various semantic tags in HTML, like <header>, <footer>, <article>, <nav>, and <main>.

HTML semantic tags are used to improve accessibility, which helps search engines to get a better understanding of your content.

Header tag in HTML

The <header> tag is a semantic element used to define the introductory content of a webpage. It contains the headings, logos, navigation menus, or other introductory information. You can use the <header> tag in the top section of a webpage.

Become a Full-Stack Web Developer
Enroll Now
quiz-icon

Example 1: <header> Inside an <article>

You can write multiple <header> tags in the code. Here is an example to show how to add a <header> tag inside an <article> in HTML.

Html

Output:

header inside article

Example 2: Simple <header> Tag

This example shows you how to use the <header> tag to define the introductory content of a website.

Html

Output:

HTML header Tag

Attributes of the <header> Tag

Attributes are defined as the special words that were used in the opening tag. These are the words that were used to provide additional information to the tags. The <header> tag is a semantic element, but it doesn’t come with any special attributes of its own. However, it supports some global HTML attributes.

Attribute Purpose
id It gives the header a unique name so that you can style it with CSS and JavaScript.
class It allows you to apply styles or behaviors using CSS or JavaScript
style It allows you to add styles directly inside the HTML.
role It helps the screen readers understand what the header is
lang It tells the browser about the language used in this part of the website.
tabIndex It controls the order when someone presses the Tab key to move around.
data-* It stores extra custom info you can use with JavaScript

Example: Using Global Attributes in the Header Tag

Html

Here, in this example, id=”main-header” and class=”top-header” both allow you to target this header element from JavaScript and a CSS file, and role=”banner” sends signals to the screen readers that this is a top-level site header.

Best Practices of Using the <header> Tag

Using the header tag properly helps in making a webpage organized and accessible. Here are some best practices that you need to follow while using the <header> tag in HTML:

  • You can use multiple <header> tags on a page. But ensure that one <header> tag is not nested inside another <header> tag.
  • Don’t place <header> inside tags like <footer> and <address>.
  • Only include titles, navigation links, and Introductory text inside the <header> element.
  • Use the role=”banner” attribute to help screen readers identify the main header of your site.

Browser Support for <header> Tag

The <header> tag is well-supported by all modern browsers. Here is the list of all browsers that support the <header> tag:

  • Internet Explorer
  • Google Chrome
  • Mozilla Firefox
  • Safari
  • Microsoft Edge
  • Opera

Get 100% Hike!

Master Most in Demand Skills Now!

Conclusion

The <header> tag is one of the important tags in Semantic HTML. It helps you to structure the introduction of a webpage. Whether you’re adding a title, branding, navigation menu, or search bar, the <header> element helps in making HTML more meaningful. It always contains headings, navigation links, and logos. By using header tags correctly, you can improve your website structure and also improve the SEO accessibility of your website.

HTML header Tag – FAQs

Q1. What is the <header> tag in HTML?

The <header> tag in HTML is used to define the top section of the webpage. It usually contains titles, logos, navigation links, or intro text.

Q2. What is the <h1> tag in HTML?

The <h1> tag in HTML represents the main heading of a page or section.

Q3. How many <header> tags are in HTML?

There’s only one <header> tag element, but you can use it multiple times in your code.

Q4. How to use a <nav> tag?

The <nav> tag is used to define a section that contains navigation links, like menus or a table of contents.

Q5. How to center a <div>?

You can use flexbox to center a div in HTML. Set align-items and justify-content to center.

About the Author

Technical Research Analyst - Full Stack Development

Kislay is a Technical Research Analyst and Full Stack Developer with expertise in crafting Mobile applications from inception to deployment. Proficient in Android development, IOS development, HTML, CSS, JavaScript, React, Angular, MySQL, and MongoDB, he’s committed to enhancing user experiences through intuitive websites and advanced mobile applications.

Full Stack Developer Course Banner