Figure, Blockquote and Citations

Beginner · 8 min

Use figure and figcaption to caption self-contained content, blockquote and q for quotations, and cite for titles, with what each shows to assistive technology.

Before thisGeneric Containers: div and span

Dave Gray · 31 min · from 17:59

Figure, Blockquote and Citations

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Dave GrayReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • `<figure>` wraps self-contained content, such as an image, a code listing or a quotation, and `<figcaption>` gives it a caption. The figure's content could move elsewhere without breaking the text around it.
  • A `figcaption` names the figure. In a test the accessibility tree reported `figure "Sales by quarter"`, taking the caption as its name, and the image inside kept its own `alt`.
  • `<blockquote>` is for a longer quotation from another source, and `<q>` is for a short inline one. In a test, `<q>` got `open-quote` from the browser's own styles, so do not type quote marks yourself.
  • The `cite` attribute on `blockquote` holds a source URL for machines and is not shown. Put the visible attribution in a `figcaption` with `<cite>` around the title of the work.
  • `<cite>` marks the title of a creative work, not the person's name. In a test it rendered italic by default.

A caption that belongs to its content

Open a textbook. A diagram appears with “Figure 3: Water cycle” under it, and the text says “see Figure 3”. The diagram has a caption and a name, and the text points at it. If you reflowed the page, the diagram could move to the next column and the text would still make sense.

HTML’s <figure> captures that. It wraps self-contained content and an optional <figcaption> that describes it:

<figure>
  <img src="sales.png" alt="Bar chart: sales rose each quarter">
  <figcaption>Sales by quarter</figcaption>
</figure>

Without figure, the caption is just a paragraph that happens to sit near an image, and software can’t tell it belongs to it. In a test with headless Chromium 159, this markup was exposed as figure "Sales by quarter" with the image inside it as img "Bar chart of sales". The caption became the figure’s name and the image kept its own text alternative. Don’t use the caption as a substitute for alt: the caption says what the figure is for, and the alt says what the image shows. The alt text lesson goes into that.

Not only images

A figure is any self-contained unit referred to from the main text: a diagram, a table, a code listing, a poem. The video has a chapter titled “figure is not just for images” for exactly this reason. A code listing with a caption is a good example:

<figure>
  <pre><code>const x = 1;</code></pre>
  <figcaption>Listing 1: a constant</figcaption>
</figure>

If you could move it to an appendix and the paragraph would still read correctly, it’s a candidate. If you couldn’t, it’s part of the flow, and a plain <p> or <img> is enough.

Quotations: blockquote and q

Two elements mark quoted text, and they differ in size.

  • <blockquote> is a longer quotation from another source, displayed as its own block. In a test it got a 40px left margin and a 16px top margin by default, and the tree reported it as blockquote.
  • <q> is a short quotation inside a sentence. Browsers draw the quotation marks for you: the generated ::before content was open-quote in the test, including for a nested <q>, whose glyph the browser picks by nesting level and language. Typing marks yourself gives you doubled quotes.

Both accept a cite attribute holding a URL for the source. It’s meant for machines, and browsers don’t show it, so the reader sees nothing. Visible credit goes in markup you can see.

Attributing the source

The common pattern combines all three:

<figure>
  <blockquote cite="https://example.com/essay">
    <p>Make it work, then make it right.</p>
  </blockquote>
  <figcaption>— Someone, <cite>An Essay on Craft</cite></figcaption>
</figure>

In a test with a similar figure (caption — <cite>Someone</cite>), the figure took the caption text as its name, the quotation inside it was a blockquote, and the paragraph kept its role. The <cite> element marks the title of a creative work, such as a book, a film or an article. It’s not for the person’s name. Default styling is italic, which I saw in the test, but the meaning is what matters, so restyle it freely. See the inline semantics lesson for the rest of the small text elements.

What the video covers

The embed is a clip, 17:59 to 25:50, from Dave Gray’s “How to Insert Images in HTML | An HTML5 Image Tutorial” (December 2021, 31 minutes). The chapters in the clip are figure and figcaption elements (17:59), adding a third image (19:58), “figure is not just for images” (23:23) and validating your HTML (25:50, the end). The earlier part of the video covers img and its attributes. It does not cover blockquote, q or cite, so those sections are this lesson’s own, from a browser test, and the deeper link is a 4-minute video on blockquote. I could not read a transcript, so I describe the clip only from the chapters.

Where this fits

This follows generic containers, the box with no meaning, with elements that do carry meaning. Next, inline semantics finishes the group with the small elements inside text. The images these figures wrap start in images and alt text.

Check yourself

  1. 01A photo has a caption underneath that the article text refers to as 'Figure 2'. Which markup fits?

    `<figure><img src="..." alt="..."><figcaption>Figure 2: ...</figcaption></figure>`. The caption is tied to the image in the markup, and in a test the figure took the caption as its accessible name. The image still needs its own `alt` describing what it shows.

  2. 02Is `figure` only for images?

    No. It is for any self-contained content that is referenced from the main flow: a diagram, a code listing, a table, a poem or a quotation. If you could move it to an appendix without breaking the text, it is a figure candidate.

  3. 03You want to show a quotation and credit the author and book. What goes where?

    The quotation goes in a `<blockquote>`, optionally with a `cite` attribute holding the source URL. The visible credit goes outside the blockquote, for example in a `figcaption`, with the book title in `<cite>`. The `cite` attribute alone is invisible to readers.

  4. 04Why not type quotation marks around a `<q>` element?

    Browsers add the marks themselves, and they follow the language. In a test the generated content for `q`, including a nested `q`, was `open-quote`. Typing your own gives double quotes. Style them with the CSS `quotes` property.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark