April 18, 201412 yr 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?
April 18, 201412 yr From the HTML spechttp://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.
April 18, 201412 yr 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.
April 18, 201412 yr 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.
April 19, 201412 yr 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.
April 19, 201412 yr 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
April 19, 201412 yr 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 April 19, 201412 yr by rbrtsmith
April 20, 201412 yr 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 April 20, 201412 yr by ~Luke
April 20, 201412 yr 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 April 20, 201412 yr by Nillervision
April 20, 201412 yr Author I see. So it is just more politically correct in terms of structure and best practise. Thanks.
April 21, 201412 yr 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 April 21, 201412 yr by rbrtsmith
June 4, 201412 yr <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