๐Ÿ“‘ Chapter 39: Content Sectioning & Advanced Semantic Architecture

figure and figcaption for Self-Contained Content

Encapsulating self-contained media, code snippets, statistical tables, quotes, and architectural diagrams.

LEARNING OBJECTIVES โŒต
  • Master the semantic definition of the <figure> element as self-contained, relocatable content.
  • Apply <figcaption> correctly as either the first or last child of a <figure> element.
  • Structure diverse media within <figure>: images, code listings (<pre><code>), statistical tables, and blockquotes.
  • Understand how screen readers calculate accessible names for the figure landmark role from <figcaption>.
๐ŸŽฌ 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)

Think of a scientific textbook on aerospace engineering.

While reading a chapter on rocket propulsion, the main body text says:

"The combustion chamber experiences extreme thermal gradients during the ignition sequence (see Figure 4.2). As the liquid hydrogen enters..."

Now imagine the graphic layout artist needs to move Figure 4.2 (the diagram of the engine nozzle with its caption) to the top of the next page, to a side callout column, or into an appendix at the end of the chapter. Does the chapter still make complete grammatical and logical sense? Yes.

MAIN FLOW DOCUMENT                             RELOCATABLE SELF-CONTAINED FIGURE
+------------------------------------+         +------------------------------------+
| The combustion chamber experiences |         | <figure>                           |
| extreme thermal gradients during   |         |   <img src="engine-nozzle.svg"     |
| ignition (see Figure 4.2).         |         |        alt="Cross-section nozzle"> |
|                                    | =====>  |   <figcaption>                     |
| As the liquid hydrogen enters the  |         |     Figure 4.2: Cryogenic cooling  |
| manifold, heat exchange occurs...  |         |     channel cross-section.         |
+------------------------------------+         |   </figcaption>                    |
                                               | </figure>                          |
                                               +------------------------------------+

A <figure> is self-contained content that is referenced as a single unit from the main flow. If you lift it out of its position and move it elsewhere, the linear text flow remains intact.


Technical Deep Dive & Specifications

The Five Real-World Permutations of <figure>

Many developers assume <figure> is only for photographs. The HTML Living Standard explicitly intends <figure> for any self-contained content unit:

+---------------------------------------------------------------------------------------------------+
|                                 DIVERSE USE CASES FOR <figure>                                    |
+---------------------------------------------------------------------------------------------------+
| 1. Media Assets: Photos, SVG diagrams, infographics, audio clips, video players.                  |
| 2. Code Listings: <pre><code> snippets referenced by "Listing 3.1: Config file".                 |
| 3. Statistical Tables: <table> datasets referenced by "Table 2: Q3 Revenue Breakdown".            |
| 4. Formal Blockquotes: <blockquote> quotes referenced by "Quote 1: Dijkstra on Simplicity".        |
| 5. Mathematical Equations & Poems: Multi-line formulas or stanzas referenced as distinct units.   |
+---------------------------------------------------------------------------------------------------+

Strict Syntax & Content Model Rules

Rule Specification Requirement Valid / Invalid Example
Placement of <figcaption> Must be either the first child or last child of <figure>. โœ… <figure><figcaption>...</figcaption><img ...></figure>
โŒ <figure><p>Text</p><figcaption>...</figcaption><p>More</p></figure>
Quantity of <figcaption> At most one <figcaption> per <figure>. โœ… 1 <figcaption> per figure
โŒ Multiple <figcaption> tags in one figure
Multiple Media Items Allowed. Multiple images can share a single caption. โœ… <figure><img ...><img ...><figcaption>Comparison</figcaption></figure>
Self-Contained Requirement Content must be capable of moving to an appendix without breaking narrative flow. โœ… Diagram referenced via "Figure 1"
โŒ Decorative icon inline within a paragraph
+-----------------------------------------------------------------------------+
|               VALID STRUCTURE A (Caption First)                             |
| <figure>                                                                    |
|   <figcaption>Listing 1: Nginx Reverse Proxy Config</figcaption>            |
|   <pre><code>proxy_pass http://upstream_cluster;</code></pre>               |
| </figure>                                                                   |
+-----------------------------------------------------------------------------+
|               VALID STRUCTURE B (Caption Last)                              |
| <figure>                                                                    |
|   <img src="chart.png" alt="Bar chart showing 40% query latency drop">     |
|   <figcaption>Figure 8: Post-migration latency distribution</figcaption>    |
| </figure>                                                                   |
+-----------------------------------------------------------------------------+

Accessibility Tree Mapping & Screen Reader Support

  1. <figure> maps to the ARIA role figure.
  2. When <figcaption> is present, browsers automatically compute the figure's accessible name from the <figcaption> text (equivalent to aria-labelledby).
  3. When a screen reader user navigates to the element, it announces: "Figure, Figure 8: Post-migration latency distribution".

๐Ÿ’ป Interactive Code Playground

Starter Code

Line-by-Line Code Breakdown

  • Line 46 (<figure class="code-listing">): Encapsulates the YAML configuration as a self-contained figure unit.
  • Line 47โ€“51 (<pre><code>...</code></pre>): Semantic markup for preformatted code.
  • Line 52 (<figcaption>Listing 1: ...</figcaption>): Caption placed as the last child of the figure, naming the listing for readers and assistive technologies.
  • Line 59 (<figure>): Encapsulates the statistical data table.
  • Line 60โ€“70 (<table>...</table>): Standard tabular data.
  • Line 71 (<figcaption>Table 1: ...</figcaption>): Links the tabular data to the narrative reference "detailed in Table 1 below".

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...
Database Replication Topologies
When deploying across multi-region availability zones, synchronous replication guarantees...

+-------------------------------------------------------------------+
| pool_config:                                                      |
|   max_open_conns: 100                                             |
|   max_idle_conns: 25                                              |
|   conn_max_lifetime: 5m                                           |
|   ssl_mode: require_secure                                        |
| ----------------------------------------------------------------- |
| Listing 1: Production database pool configuration yaml            |
+-------------------------------------------------------------------+

Benchmark results across 50,000 concurrent write operations are detailed in Table 1 below.

+-------------------------------------------------------------------+
| Replication Mode        | P50 Latency | P99 Latency | Data Loss   |
| Asynchronous            | 1.2 ms      | 4.8 ms      | Non-Zero    |
| Semi-Synchronous        | 4.5 ms      | 12.1 ms     | Bounded     |
| Full Synchronous (Raft) | 8.9 ms      | 18.4 ms     | Zero (RPO=0)|
| ----------------------------------------------------------------- |
| Table 1: Replication latency benchmarks across 3 AWS regions      |
+-------------------------------------------------------------------+

๐Ÿ‹๏ธ Hands-On Exercise

๐ŸŽฏ The Challenge: Build a Multi-Image Architecture Comparison Figure

Instructions:

  1. Create a single <figure> containing two architecture diagram images side-by-side: monolith.svg and microservices.svg.
  2. Include a single <figcaption> placed as the first child of the <figure>.
  3. The caption should read: "Figure 3: Transition from Monolithic MVC to Event-Driven Microservices Architecture."
  4. Ensure both images have comprehensive alt attributes explaining their visual contents.

๐Ÿ 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 <figcaption> in the Middle: Placing <figcaption> between two images or between text paragraphs. The specification strictly allows <figcaption> to be ONLY the first child or last child of <figure>.
  2. Using <figure> for Purely Decorative Images: Wrapping hero background banners or small UI icons in <figure>. Decorative images belong in CSS or standard <img> tags with alt="". <figure> is exclusively for self-contained reference units.
  3. Redundant Alt Text Matching Caption Exactly: Setting alt="Figure 1: Rocket engine" on the image when <figcaption>Figure 1: Rocket engine</figcaption> is already present. Screen readers will read the exact same sentence twice in a row. Instead, use alt to describe the visual details and <figcaption> to provide the editorial label.

๐Ÿ’ก Pro Tips

  1. Printing & Academic CSS Pagination: CSS paged media rules (break-inside: avoid;) work seamlessly with <figure>, ensuring diagrams or code snippets are never awkwardly split across two physical pages when exported to PDF:
    @media print {
      figure {
        break-inside: avoid;
        page-break-inside: avoid;
      }
    }
    
  2. Blockquotes with Attribution: When creating formal pull quotes, pair <blockquote> inside <figure> and place the author citation inside <figcaption>:
    <figure>
      <blockquote>
        <p>"Simplicity is prerequisite for reliability."</p>
      </blockquote>
      <figcaption>โ€” Edsger W. Dijkstra, <cite>Selected Writings on Computing</cite></figcaption>
    </figure>
    

๐Ÿ“Œ Key Takeaways

  • <figure> represents self-contained content referenced from the main flow that could be relocated without disrupting meaning.
  • <figure> supports diverse content: images, code snippets (<pre><code>), tables, blockquotes, and diagrams.
  • <figcaption> must be placed as either the first child or last child of the <figure>.
  • Only one <figcaption> is permitted per <figure>, but multiple media items may be grouped under that single caption.
  • Assistive technologies derive the accessible name of the figure landmark directly from the <figcaption>.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

Where may a <figcaption> element be legally positioned within a <figure> according to the WHATWG specification?

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

Why is it an accessibility anti-pattern to set an image's alt attribute to the exact duplicate text of the <figcaption>?

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 content types is valid inside a <figure> element?

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