๐Ÿ“‘ Chapter 6: Headings & Paragraphs

The hgroup Element

Master the modernized WHATWG standard for `<hgroup>`, pairing primary headings with subtitles, taglines, and alternative titles without polluting the document outline.

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.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– 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:

  1. 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.
  2. 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>).
  • 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


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...
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:

  1. Wrap the publication's main header title and issue tagline in a modern <hgroup>.
  2. Refactor each <article> header to use an <hgroup> wrapping its <h2> title and its subtitle <p>.
  3. Eliminate all false <h3> and <h4> tags used purely for subtitles.
  4. Ensure the resulting document outline has exactly one <h1> and three clean <h2> article sections.

๐Ÿ Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. 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.
  2. Placing Non-Paragraph Content Inside <hgroup>: Putting <div>, <img/>, or <ul> inside <hgroup>. Only headings, <p> tags, and <script>/<template> tags are permitted.
  3. 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

  1. 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;
    }
    
  2. 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.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

Under the current WHATWG Living Standard, what is the valid content model for an <hgroup> element?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What problem is solved by using <hgroup><h1>Title</h1><p>Subtitle</p></hgroup> instead of <h1>Title</h1><h2>Subtitle</h2>?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

Which of the following code snippets is INVALID according to the modern <hgroup> specification?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP