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
figurelandmark role from<figcaption>.
๐ 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
<figure>maps to the ARIA rolefigure.- When
<figcaption>is present, browsers automatically compute the figure's accessible name from the<figcaption>text (equivalent toaria-labelledby). - 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
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:
- Create a single
<figure>containing two architecture diagram images side-by-side:monolith.svgandmicroservices.svg. - Include a single
<figcaption>placed as the first child of the<figure>. - The caption should read: "Figure 3: Transition from Monolithic MVC to Event-Driven Microservices Architecture."
- Ensure both images have comprehensive
altattributes explaining their visual contents.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- 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>. - 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 withalt="".<figure>is exclusively for self-contained reference units. - 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, usealtto describe the visual details and<figcaption>to provide the editorial label.
๐ก Pro Tips
- 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; } } - 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
figurelandmark directly from the<figcaption>. - --