Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

HTML5 <header> tag

Featured Replies

I have seen some sites use multiple <header> tags - I would have thought HTML5 would use just one header tag to identify the 'header' at the top of the site and that's that.

 

My question is... What is the <header> tag actually for? What does it do or distinguish differently to a div or class container being used for a header?

From the HTML spec

http://www.w3.org/TR/html51/sections.html#the-header-element

 

The header element represents introductory content for its nearest ancestor sectioning content or sectioning root element. A header typically contains a group of introductory or navigational aids.

When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.

A header element is intended to usually contain the section's heading (an h1–h6 element), but this is not required. The header element can also be used to wrap a section's table of contents, a search form, or any relevant logos.

The header element is not sectioning content; it doesn't introduce a new section.

 

It also carries the ARIA role of banner by default.

 

  • Author

Thanks for the reply and info.

 

I still don't really get what the difference would be between using a header tag or standard div formatted as required through CSS to be a header.

The difference is that the header tag has a meaning, as quoted above, an introduction either to the page as a whole or to a specific section. A div is just a generic container that has no meaning, adding style to a div doesn't change that.

hiii,

 

 

Header Tag is the main tag of html. In header tag you can add css, java script, to the html file.

 

you can add in body div and class .

 

Header and Body are the main two parts of HTML.

hiii,

 

 

Header Tag is the main tag of html. In header tag you can add css, java script, to the html file.

 

you can add in body div and class .

 

Header and Body are the main two parts of HTML.

er, you mean <head>

we're talking about <header>. different thing altogether ;)

You can have multiple headers, footers and even h1's throughout a single html5 web page, but each one should be in a seperate grouping tag, such as a section, article or an aside.

 

<body>

<header>
  <h1>Site title</h1>
</header>
<article>
  <header>
    <h1>Article title</h1>
  </header>
  <p>Article content.........</p>
  <footer>
    <p>Blah</p>
  </footer>
</article>
<footer>
  <p>site footer</p>
</footer>

</body>

The above is perfectly valid html5 markup.

Edited by rbrtsmith

  • Author

Thanks, my question is what does HTML5 do differently with the header, nav, aside, footer tags as opposed to me just using containers with the relevant CSS formatting for each?

 

If you were to say its treats the header like a header, nav like navigation, etc.. How so?

Edited by ~Luke

Thanks, my question is what does HTML5 do differently with the header, nav, aside, footer tags as opposed to me just using containers with the relevant CSS formatting for each?

 

If you were to say its treats the header like a header, nav like navigation, etc.. How so?

Using a header tag is not about how your site is displayed. The browser will render it like every other block element. As Wynn explained its all about meaning. Placing content in the correct tags gives semantic structure to your site and will make it easier for search engines to index. You shouldn't think about choosing tags for display but for structure and meaning. As an example: Say you want your all your h1 tags on the page to be smaller. It would be bad practice to change all h1's to h3's as the h1 tag has more semantic weight. You would simply change the font-size on h1 with css. Just like the h1 tag, a header tag has semantic weight in contrast to a div.

Edited by Nillervision

  • Author

I see. So it is just more politically correct in terms of structure and best practise. Thanks.

HTML5 tags

 

Firstly they're useful for SEO purposes as it can give the google crawlers a better idea about the content of your website and what is important.

 

Secondly they're is good for accessibility, devices like screenreaders can alert the user to what is an article, what is a nav etc.

 

Thirdly they're makes your code easier to read, even with good indentation usage if you have 15 nested divs it becomes harder to read.

Edited by rbrtsmith

  • 1 month later...

<header> tag is the tag element of html5.

this can be used to display the content on the top of the section.

syntax:

<html>

<head>

</head>

<body>

<header>

</header>

<section>

<header>

</header>

</section>

<section>

<header>

</header>

</section>

</body>

</html>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.