HTML <hgroup> Tag
<hgroup> element allows you to attach a subtitle to a title without the subtitle being added to the document outline.
For example, you might have a level 1 heading, followed by a subheading in a level 2 heading. In this instance, the level 2 heading is different to the other level 2 headings in the document because it is an extension of the level 1 heading (i.e. it is a subheading of the heading).
Avoid this element if you need to make your documents W3C-compliant. See below for a "W3C-compliant" option.
<hgroup> tag is written as
</hgroup> with the grouped headings enclosed between the start and end tags.
Before we look at the examples, let's make sure we understand the problem first.
You could quite easily use two headings to represent a title and its subtitle without using the
<hgroup> tag. Like this:
However, this would result in both headings being added to the document outline. This means that, semantically, the two headings start their own section or subsection. Therefore, the subtitle will represent a new section. This may or may not be your intention.
So if your intention is for the subtitle/subheading/tagline etc to be added to the document outline, you don't need to use the
<hgroup> tag. You can simply use another heading element (
<h6>) to mark up the subtitle/subheading.
Because the headings are not contained within the
<hgroup> element, the 2nd heading will appear in the document outline.
If it is not your intention to add the subtitle to the document outline (start a new section), you have 3 options:
- use the
<hgroup>tag (not W3C-compliant)
- use a non-heading element for the subtitle (W3C-compliant)
- include the subtitle in the same heading element as the title (W3C-compliant)
<hgroup> Tag Usage
By enclosing the heading elements inside the
<hgroup> element, the
<h2> element is not added to the document outline.
Remember, the purpose of the
<hgroup> element is to mask the subtitle/subheading etc from the document outline (this prevents it from appearing in a table of contents).
HTML5 (i.e. the W3C version of HTML) doesn't support the
<hgroup> element. Only the WHATWG version (HTML Living Standard) supports this element. Therefore, if you need to make your documents W3C-compliant, you won't be able to use this element.
Also, W3C explicitly states that
must not be used to markup subheadings, subtitles, alternative titles and taglines unless intended to be the heading for a new section or subsection.
If you do not want the subtitles to be included the document outline (table of contents) and they are not intended to signify the start of a new section, check out the examples below.
You could also use CSS to style the subtitle if desired.
You could include the subtitle in the same heading as the title, separated by a colon.
You could take the previous example a step further by adding a
<br> tag and a
<span> tag to separate the subtitle from the title. This will enable you to separate the styles between the title and subtitle.
Attributes can be added to an HTML element to provide more information about how the element should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.
<hgroup> element accepts the following attributes.
This table shows the attributes that are specific to the
The following attributes are standard across all HTML5 elements. Therefore, you can use these attributes with the
<hgroup> tag , as well as with all other HTML tags.
For a full explanation of these attributes, see HTML 5 global attributes.
Event Handler Content Attributes
Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.
Below are the standard HTML5 event handler content attributes.
Again, you can use any of these with the
<hgroup> element, as well as any other HTML5 element.
For a full explanation of these attributes, see HTML 5 event handler content attributes.
Differences Between HTML 4 & HTML 5
<hgroup> element doesn't actually exist in HTML 4 or the HTML5 specification. The element was introduced (and subsequently dropped) in HTML 5.
<hgroup> element is included in the WHATWG Living Standard specification.
For more details on the element, see HTML5
Here's a template for the
<hgroup> tag with all available attributes for the tag (based on HTML5). These are grouped into attribute types, each type separated by a space. In many cases, you will probably only need one or two (if any) attributes. Simply remove the attributes you don't need.
For more information on attributes for this tag, see HTML5
For more details about the
<hgroup> tag, see HTML5
Here are the official specifications for the
- HTML Living Standard (WHATWG)
What's the Difference?
W3C creates "snapshot" specifications that don't change once defined. So the HTML5 specification won't change once it becomes an official recommendation. WHATWG on the other hand, develops a "living standard" that is updated on a regular basis. In general, you will probably find that the HTML living standard will be more closely aligned to the current W3C draft than to the HTML5 specification.