hgroup element | hgroup object
[This documentation is preliminary and is subject to change.]
Represents the heading of a section.
![]() |
Standards information
There are no standards that apply here.
HTML information
| Closing Tag | required |
|---|---|
| CSS Display | block |
DOM Information
Inheritance Hierarchy
Remarks
Windows Internet Explorer 9. The hgroup element is only supported for webpages displayed in IE9 Standards mode. For more information, see Defining Document Compatibility.
The hgroup element is used to group a set of h1-h6 elements when the heading has multiple levels, such as subheadings, alternative titles, or taglines. Other elements of heading content in the hgroup element indicate subheadings or subtitles.
Examples
The following is an example of a valid heading. The hgroup masks the h2 element (which acts as a secondary title) from the outline algorithm.
<hgroup> <h1>Dr. Strangelove</h1> <h2>Or: How I Learned to Stop Worrying and Love the Bomb</h2> </hgroup>
For document summaries and outlines, the text of hgroup elements is defined as the text of the highest ranked h1-h6 element descendant, or the first such element if there are multiple elements with the highest rank. If there are no such elements, then the text of the hgroup element is the empty string. The following script demonstrates how to implement this behavior.
function findHeadings(node)
{
// First check if this node has an <hgroup>.
var hg = node.getElementsByTagName("HGROUP");
if(hg.length>0)
node = hg[0];
// Now find the highest ranking heading.
var ranks = [ "H1","H2","H3","H4","H5","H6" ];
for (var i=0; i<ranks.length; i++) {
var headings = node.getElementsByTagName(ranks[i]);
if(headings.length>0)
return headings[0].textContent;
}
// No headings present, return empty string.
return "";
}
See also
Build date: 3/8/2012
