LEARNING OBJECTIVES โต
- Understand the historical evolution of
<hgroup>from its 2013 deprecation to its modern WHATWG Living Standard revitalization. - Implement modern
<hgroup>markup pairing a primary heading (<h1>โ<h6>) with secondary<p>subheadings and taglines. - Explain how
<hgroup>prevents outline pollution and protects the accessibility tree from false heading nodes. - Identify valid and invalid children inside an
<hgroup>container according to current W3C/WHATWG specifications.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine browsing a movie theater poster for a major Hollywood blockbuster:
==============================================
INCEPTION
"Your mind is the scene of the crime"
==============================================
The word "INCEPTION" is the title of the film (<h1>).
The sentence "Your mind is the scene of the crime" is the catchy tagline/subheading.
If a web developer marks up that tagline as an <h2>, what does the document outline look like?
Broken Outline (Tagline as H2): Clean Outline with <hgroup>:
+-----------------------------------+ +-----------------------------------+
| <h1> Inception </h1> | | <hgroup> |
| โโโ <h2> "Your mind is the..." | | <h1> Inception </h1> |
| โโโ <h2> Plot Summary </h2> | | <p> "Your mind is the..." </p> |
| โโโ <h2> Cast & Crew </h2> | | </hgroup> |
+-----------------------------------+ | <h2> Plot Summary </h2> |
(The tagline is falsely indexed as a | <h2> Cast & Crew </h2> |
major topical section of the movie!) +-----------------------------------+
(The tagline is bound to the title
without polluting the outline!)
A tagline or subtitle is not a new structural section of the page; it is descriptive metadata belonging to the main title.
Using an <h2> for a subtitle introduces outline pollution, forcing screen readers and search engines to treat the subtitle as a standalone topical chapter. The modern <hgroup> element provides the perfect semantic container to bind titles and subtitles together.
Technical Deep Dive & Specifications
The History: Deprecation and Revival of <hgroup>
The <hgroup> element has one of the most fascinating histories in the HTML standard:
- HTML5 (2008โ2013): Originally designed to contain multiple heading tags (e.g.,
<hgroup><h1>Title</h1><h2>Subtitle</h2></hgroup>). Screen reader vendors refused to hide the<h2>from the outline, causing widespread accessibility failures. The W3C deprecated<hgroup>in 2013. - WHATWG Revival (2020โPresent): The WHATWG redefined
<hgroup>with a brand-new content model. Instead of containing multiple headings, it contains exactly one heading (<h1>โ<h6>) paired with one or more<p>elements representing subtitles, alternative titles, or taglines.
+-------------------------------------------------------------+
| MODERN <hgroup> CONTENT MODEL |
+-------------------------------------------------------------+
| <hgroup> |
| <h1>Main Document Title</h1> โโโ Exactly ONE Heading |
| <p>Secondary Subtitle</p> โโโ One or more <p> tags |
| <p>Catchy marketing tagline</p> |
| </hgroup> |
+-------------------------------------------------------------+
WHATWG Specification Rules for <hgroup>
According to the modern WHATWG Living Standard:
- Allowed Children:
- Exactly one heading element (
<h1>,<h2>,<h3>,<h4>,<h5>, or<h6>). - Zero or more
<p>elements representing subheadings, subtitles, alternative titles, or taglines. - Script-supporting elements (
<script>,<template>).
- Exactly one heading element (
- Forbidden Children: You cannot place arbitrary
<div>,<section>,<ul>, or<button>elements directly inside an<hgroup>.
Accessibility Tree Mapping & Screen Reader Support
Modern browsers map <hgroup> to the accessibility tree as a group landmark or semantic container.
DOM Tree: Accessibility Object Model (AOM):
<hgroup> โโโโบ Role: group
<h1>Autonomous Robotics</h1> โโโ Role: heading, Level: 1, Name: "Autonomous Robotics"
<p>Principles of SLAM</p> โโโ Role: paragraph, Content: "Principles of SLAM"
</hgroup>
When a screen reader user navigates by headings (pressing H), the reader lands on "Autonomous Robotics (Heading Level 1)". The subtitle is immediately available in the sequential reading buffer without cluttering the heading list.
Comparison: Subheading Markup Patterns
| Approach | HTML Markup | Outline Cleanliness | Accessibility Score | Modern Spec Compliance |
|---|---|---|---|---|
Modern <hgroup> Standard |
<hgroup><h1>Title</h1><p>Subtitle</p></hgroup> |
โ Pristine | ๐ข Optimal (A+) | โ Living Standard |
Subtitle as <h2> |
<h1>Title</h1><h2>Subtitle</h2> |
โ Polluted | ๐ด Poor (Misleading) | โ ๏ธ Unsemantic for subtitles |
Subtitle as Raw <p> |
<h1>Title</h1><p class="sub">Subtitle</p> |
โ Clean | ๐ก Acceptable | โ Valid, but lacks explicit grouping |
<span class="sub"> inside <h1> |
<h1>Title <span class="sub">Sub</span></h1> |
โ Clean | ๐ก Acceptable | โ Valid, but announces as single huge title |
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Lines 51โ55 (
<hgroup>...</hgroup>): The semantic group wrapper enclosing the article's complete title block. - Line 52 (
<p class="tagline">Research Publication โข Issue 42</p>): A pre-title eyebrow/tagline marked up as a semantic paragraph rather than an unsemantic<h6>. - Line 53 (
<h1>Quantum Supremacy in Cryptography</h1>): The single primary heading element inside the group. - Line 54 (
<p>Analyzing post-quantum lattice-based encryption...</p>): The detailed subtitle marked up as a paragraph inside<hgroup>, preventing it from appearing as a false<h2>in the outline. - Lines 58 & 65 (
<h2>1. The Threat...</h2>,<h2>2. Lattice-Based...</h2>): The actual structural Level 2 sections follow cleanly, maintaining an immaculate document outline.
Expected Browser Render Output
RESEARCH PUBLICATION โข ISSUE 42
Quantum Supremacy in Cryptography (Bold large title)
Analyzing post-quantum lattice-based encryption algorithms against Shor's algorithm.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. The Threat to Public-Key Infrastructure (Medium bold section title)
Shor's algorithm theoretically solves integer factorization...
2. Lattice-Based Cryptographic Candidates (Medium bold section title)
The National Institute of Standards and Technology (NIST)...๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Refactor a Magazine Headline Block
A digital magazine website was designed with subtitles coded as <h3> tags directly underneath <h1> and <h2> headings. As a result, screen readers announce 18 different heading levels on a 3-article page.
Instructions:
- Wrap the publication's main header title and issue tagline in a modern
<hgroup>. - Refactor each
<article>header to use an<hgroup>wrapping its<h2>title and its subtitle<p>. - Eliminate all false
<h3>and<h4>tags used purely for subtitles. - Ensure the resulting document outline has exactly one
<h1>and three clean<h2>article sections.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Placing Multiple Headings Inside
<hgroup>: Writing<hgroup><h1>Main Title</h1><h2>Subtitle</h2></hgroup>. This violates the modern WHATWG specification. Use a<p>for the subtitle instead. - Placing Non-Paragraph Content Inside
<hgroup>: Putting<div>,<img/>, or<ul>inside<hgroup>. Only headings,<p>tags, and<script>/<template>tags are permitted. - Using
<hgroup>on Every Single Heading: Wrapping solitary<h2>tags with no subtitles inside an empty<hgroup>. Only use<hgroup>when grouping a heading with accompanying subtitle/tagline<p>elements.
๐ก Pro Tips
- CSS
:has()Synergy with<hgroup>: You can use modern CSS:has()to dynamically adjust heading margins only when a subtitle<p>is present:/* Tighten heading bottom margin if followed by a subtitle paragraph */ hgroup:has(p) :is(h1, h2, h3) { margin-bottom: 0.25rem; } - SEO Metadata Extraction: Search crawlers frequently inspect
<p>elements inside<hgroup>to generate secondary rich snippet descriptions beneath titles in SERP cards.
๐ Key Takeaways
- The modern WHATWG standard defines
<hgroup>as a container for exactly one heading (<h1>โ<h6>) paired with one or more<p>elements. <hgroup>solves the outline pollution problem by preventing subtitles from generating false heading nodes in the accessibility tree.- The legacy HTML5 pattern of putting multiple heading tags (
<h1>+<h2>) inside<hgroup>is obsolete and should not be used. - Only headings,
<p>,<script>, and<template>elements are legally permitted children of<hgroup>. - Screen readers announce the primary heading without breaking heading list navigation.
- --