HTML5 structure—header, hgroup & h1-h6
Note: I’ve moved all my HTML5 articles to http://oli.jp/, so I can walk the walk. I’ll leave this here for posterity, but won’t update it.
→ Go to:
“HTML5 structure—header, hgroup & h1-h6” on oli.jp
In the previous article I discussed the differences between <div>, <section> and <article>. The next pair of new HTML5 elements I’ll discuss are <header> and <hgroup>:
<header>—a container element for a section’s introductory and navigational content. Thistypically contains the section’s heading (an
. Note that this element can be used in any section of the page (except a<h1>-<h6>element or an<hgroup>element), but can also contain other content, such as a table of contents, a search form, or any relevant logos<footer>or in another<header>), and is not only for the ‘page header’ containing the logo etc. (W3C:HTML, WhatWG)<hgroup>—a specialised form of<header>that must contain a group (at least two) of<h1>-<h6>elements, and nothing else. It is for grouping a title with subtitle(s). Make sure to maintain<h1>-<h6>hierarchy—think of a nested outline. (W3C:HTML, WhatWG)<h1>-<h6>—the heading elements from HTML4 are back and basically unchanged(*), except for HTML5’s stronger guidance on using them correctly (ie don’t skip levels). Note that a single<h1>-<h6>doesn’t require a<header>wrapper. (W3C:HTML, WhatWG)
While <header> and <hgroup> are easy to confuse, remember that <hgroup> can only contain a ‘heading group’ of <h1>-<h6> elements, and is for subtitles, alternative titles, or taglines
. <header> can contain a <h1>-<h6> element or <hgroup> in addition to other elements that introduce the section. If there’s no need for an <hgroup> subtitle or other <header> content, just use the relevant <h1>-<h6> element.
An article with one title#
<!-- Title h1 only—no hgroup or header needed -->
Article title
Content…
A article header with title and metadata#
<!-- Wrapping title and metadata in header -->
Article title
(13th July, 2009)
Content…
An article with an <hgroup>-enclosed subtitle#
<!-- Title h1 and subtitle h2 in hgroup -->
Article title
Article subtitle
Content…
A article with title, subtitle and metadata#
<!-- A heading which uses header and hgroup -->
Article title
Article subtitle
(13th July, 2009)
Content…
Some examples of <hgroup> use#

An article title with an alternative title

A site name with tagline (branding phrase)

A long article title split into title and subtitle
Using <header> for the page header#
It’s possible to use <header> for the page header (and <footer> for the page footer too). However, while <header> can contain sectioning elements, it can’t contain <header> or <footer>. For a complex page header or footer that requires nested sectioning elements with their own headers and footers use <section> instead.
HTML5-style heading element levels#
In HTML authors should use the heading elements <h1>-<h6> rationally—using the levels to indicate nesting and not skipping levels—but this can be a problem in long or complex documents. Also there are some documents that actually need more than six levels of headings! (actually I always wondered what became of poor <h7>-<h9> :) In HTML5 there are now two ways we can use headings;
- as in HTML4 with
<h1>being the page or article title (or both—nothing says you must only have one<h1>element) and subsequent headings increasing as required - & a new way where each section begins with
<h1>again
This new way is potentially much easier as most sections will only need one heading element, which means <h1> (almost) everywhere. However current browsers won’t interpret this correctly (eg when CSS is disabled), so unless you actually need more than six levels it’s probably best to stick with the old style for the present.
Example of nesting heading element levels#
<!-- Standard nesting of heading elements (uses h1 to h4) -->
Article title
Article subtitle
Section title
Content…
Subsection title
Content…
Example of new-style heading element levels#
<!-- HTML5-style heading levels—new section resets (uses h1 and h2) -->
Article title
Article subtitle
Section title
Content…
Subsection title
Content…
In the next exciting installment, the last of the structural tags and a look at sectioning elements and outlines…
Questions? Feedback? Mistakes? Let me know via Twitter (@boblet)…
Changes:#
- 2009-07-07 Added links to some other HTML5 articles I’ve written
- 2009-07-13 Added text about using
<header>as the page header and improved<header>’s description - 2009-07-14 Added new
<header>&<header>+<hgroup>code examples, and removed the unnecessary wrapping<header>in several code examples (1, 2, 3) - 2009-07-22 Added missing
<code>elements that had prevented the example code coloring from working for some examples after a CSS change. Changed from HTML5 to HTML 5 etc. - 2009-09-12 Changed back from HTML 5 to HTML5 etc :| Also added anchors to titles (on hover) and made a couple of small clarifications.
Notes
-
vfreeappsnh likes this
-
wordpress-developers-uk reblogged this from boblet
-
wordpress-developers-uk likes this
-
psdtohtmlshop reblogged this from boblet
-
dilawaronline likes this
-
trampoline3f reblogged this from boblet
-
xn----slbefavdc9aecr2ax8cfbiip9g reblogged this from boblet
-
lewesde reblogged this from boblet
-
cubiertas-para-piscinas likes this
-
brazzers-passwords reblogged this from boblet
-
learning-spanish-easily likes this
-
tokyo-japan-life likes this
-
tipifam likes this
-
alancechrealtor likes this
-
digi-article-blaster likes this
-
about-chihuahua likes this
-
french-translator likes this
-
last--minute likes this
-
fertilizerspreader likes this
-
boblet posted this