skip to content

In current HTML, what is the <hgroup> element for, and how would you mark up a page title that has a subtitle or tagline underneath it?

level: middleimportance: nice to knowfreq 26%

answer

  1. title plus tagline, one unit
  2. a subtitle is not a section
  3. one heading, then paragraphs
  4. the multi-heading version is history
  5. adds no level of its own

basics

~20 s

Modern <hgroup> wraps exactly one heading plus one or more <p> elements holding its subtitle or tagline. It groups them as related content; it does not create a heading of its own or change the heading's level.

solid answer

~50 s

`<hgroup>` today means "a heading together with content that belongs to it": its content model is one `h1`–`h6` element, optionally intermixed with one or more `<p>` elements. So a page title with a tagline is an `h1` and a `p` inside an `hgroup`. The important part is what it does *not* do — it does not add a level, and it does not hide anything. Its original HTML5 definition was different: it could hold several headings, and the never-implemented outline algorithm would treat the highest-ranked one as the group's heading while suppressing the rest. That behaviour never shipped, so the old habit of writing `<h1>Title</h1><h2>Subtitle</h2>` inside an `hgroup` produced a real, announced level-2 heading that polluted the outline. If you are unsure, `hgroup` is optional — an `h1` followed by a plain `p` is perfectly correct markup.

code

html · 9 lines
html
<hgroup>
  <h1>Northwind Coffee</h1>
  <p>Roasted the week you order it</p>
</hgroup>

<section>
  <h2>Our roasts</h2>
  <p>Six single origins, rotating monthly.</p>
</section>

go deeper

for a junior

Know that a subtitle or tagline is a paragraph, not a heading, and that hgroup is simply a wrapper you can put around a title and its tagline.

for a middle

State the current content model — one h1-h6 plus one or more p elements — and explain why the old multi-heading form was redefined once the outline algorithm was dropped.

for a senior

Show judgment about where subtitle text lands: inside the heading it joins the accessible heading text and the headings list, outside it does not, and that choice affects how skimmable the page is.

for a principal

Own the pattern at design-system level so title-plus-tagline components cannot emit phantom headings, and be ready to explain why an element's meaning changing over time is a reason to check the current spec rather than trust old examples.

## The problem hgroup exists for A title with a tagline under it is one editorial unit but two lines of text: > **Northwind Coffee** > *Roasted the week you order it* The tagline is not a section of the page, so it must not be a heading. But it is also not free-floating body copy — it belongs to the title. `<hgroup>` is the element that says so. ## The current content model In the HTML Living Standard, `hgroup` contains **one** heading element (`h1`–`h6`), optionally intermixed with **one or more `p` elements**. Nothing else. The `p` elements may come before or after the heading. ```html <hgroup> <h1>Northwind Coffee</h1> <p>Roasted the week you order it</p> </hgroup> ``` The heading inside is an ordinary heading at its stated rank. `hgroup` adds no rank of its own, removes none, and hides nothing. It is a grouping wrapper whose payoff is that the relationship between the title and its subtitle is expressed in markup rather than only in CSS proximity. ## The old definition, and why the difference matters This is the part interviewers probe, because the element changed meaning. In the original HTML5 definition, `hgroup` could contain **several** heading elements, and the document outline algorithm was supposed to collapse them: the highest-ranked heading became the group's heading and the rest were suppressed from the outline. That is where this very common pattern came from: ```html <!-- the old, now-invalid pattern --> <hgroup> <h1>Northwind Coffee</h1> <h2>Roasted the week you order it</h2> </hgroup> ``` Since the outline algorithm was never implemented by any browser or screen reader, no suppression ever happened. The markup above produced exactly what it says: a level-1 heading followed by a real level-2 heading whose text is a marketing tagline. Every user navigating by heading found a phantom section. When the outline algorithm was removed from the standard, `hgroup` was redefined to the single-heading-plus-paragraphs model, which is honest about what implementations actually do. So the interview-worthy statement is: **a subtitle is never a heading.** Whatever wrapper you use, the second line is a `p`. ## Alternatives, and when to use which `hgroup` is optional. All three of these are defensible: 1. **Plain heading plus paragraph, no wrapper.** Simplest, and correct. Use it when the CSS does not need a grouping hook. 2. **`hgroup` around them.** Use it when you want the relationship stated in markup and a container to style. 3. **Subtitle inside the heading**, usually as a `span`: ```html <h1>Northwind Coffee <span class="tagline">Roasted the week you order it</span></h1> ``` Option 3 has a consequence worth knowing: the subtitle text becomes part of the heading's own text, so it is announced as part of the heading and appears in a screen reader's headings list with the tagline attached. That is fine when the subtitle genuinely completes the title ("Chapter 4: The Long Winter") and unhelpful when it is decorative marketing copy that makes every list entry long. Choose based on whether a user skimming the headings list wants those extra words. ## Practical guidance - Use a heading for anything that is a section title, and a `p` for anything that is not. - Reach for `hgroup` when a title-plus-tagline pairing is real and you want it grouped; skip it otherwise, since nothing breaks without it. - Never put two headings in an `hgroup` expecting one to be suppressed — that behaviour never existed and the markup is no longer valid. - Keep the rank of the heading inside `hgroup` driven by the page's structure, exactly as it would be outside one.

  • Why was the old pattern of an h1 and an h2 inside hgroup actively harmful rather than merely redundant?
    Because the suppression it relied on never existed. The `h2` was announced as a genuine level-2 heading, so anyone navigating by heading hit a section that has no content — a tagline masquerading as structure. It also consumed the level that the page's first real section should have used.
  • What changes if you put the subtitle in a <span> inside the h1 instead?
    The subtitle becomes part of the heading's own text, so it is announced with the heading and shows up in the headings list attached to it. That is right when the subtitle completes the title and wrong when it is decorative copy, because it makes every list entry long and less scannable.
  • Is hgroup required for a title-and-tagline pairing?
    No. A heading followed by a plain `p` is entirely correct and is what most pages ship. `hgroup` is a way to state the grouping in markup and give CSS a container; nothing about accessibility or validity depends on using it.

saying these in an interview costs you the question

  • Puts an h2 subtitle inside hgroup expecting it to be hidden
  • Thinks hgroup itself acts as a heading
  • Believes hgroup changes the level of the heading inside it
  • Marks any decorative tagline as a heading element
  • Claims hgroup can contain several headings today

context